Let's say I have models: User and Item and relation many-to-many between them. How to get Users who have exactly(no more) Items with the defined attributes i.e. Users who have Items with colors = ['red', 'black'].
Of course I can do something like this:
User.all :joins => [:items, :items], :conditions => {:"items.color" => "red", :"items_users.color" => 'black'}
But for more attributes it's going to be quite cumbersome. I can do also:
User.all(:conditions => ["items.color in (?), ['red', 'black']], :include => :items)
But this one returns also users with items having colors = ['red', 'black', 'blue', 'etc']
So the only solution is to get all and to sort with ruby syntax ? How to do it in one SQL query or Rails AR syntax ?