Complement set association to has_many/through?


#1

I have two models, A and B, with a straightforward many-to-many
has_many/through association between them. So, in A I have the
association processed_bs and in B I have processedby_as. This works
fine.

Now, I would like to also have an association unprocessed_bs in A,
which holds all Bs that aren’t in processed_bs. I can write a method
in A that returns all those objects as a list (using
B.find(:all,:conditions)), but that’s an assymetric and not very
pleasing solution. For example it means that I can to
aobj.processed_bs.count but not aobj.unprocessed_bs.count. Which is
clearly ugly.

I’ve tried playing around with feeding various variants of :select and
:finder_sql to the has_many declaration, but so far only produced lots
of different tracebacks. I’ve also got this ugly feeling that writing
that much SQL is an invitation to problems when/if I want to switch
databases.

So is there a neat way to get the complement set to an existing
association?


Calle D. removed_email_address@domain.invalid
http://www.livejournal.com/users/cdybedahl/
“Data on the network has cooties and will EAT YOUR BRAINS”
– Ross Younger, BofhNet