Querying empty Datamapper has n relationships [duplicate]
In my Rails app I have two models: Briefing and Company. Briefing has n, :companies, :through => Resource and Company has n, :briefings, :through => Resource.
I'm trying to find all the briefings that have don't have any companies associated with them. As incorrect code this might look something like:
Briefing.all( :companies => nil )
or
Briefing.all( :companies.eql => [] )
but of course those don't work. Any thoughts?
I believe Dan just pushed a change that makes possible to run such a query. So if you have a User.has n, :posts and you run a query like that:
User.all(:posts => nil)
Then the generated SQL will look like that:
SELECT "id" FROM "users" WHERE NOT("id" IN (SELECT "user_id" FROM "posts")) ORDER BY "id"
This will be available in DataMapper 1.1.1
精彩评论