I have a sql code that will print out all events that user with id=3 did not join particular yet:
SELECT * from Event where id not in (select event_id from Participant where user_id =3);
I want to write it in SQLAlchemy and so far I've got this
Event.query.filter(not_(Participant.user_id==3))
but produced query is not what I initially wrote:
SELECT "Event".id AS "Event_id",
"Event".name AS "Event_name",
"Event".published AS "Event_published",
"Event".published_when AS "Event_published_when",
"Event".published_by AS "Event_published_by"
FROM "Event", "Participant"
WHERE "Participant".user_id != ?
The above is not giving any results. I guess I wrote this SQLAlchemy query incorrectly. What is wrong with it?