Am I trying to do something silly here, as I can't figure out the best way to do it.

I have the following models:

Account > has_many Companies Company > has_and_belongs_to_many Accounts Project > has_and_belongs_to_many Companies

I want to get all the companies that are assigned to a given account but are not assigned to a given company, do I have to use a custom SQL find in the model or is there an easier way?

-D

Account > has_many Companies Company > has_and_belongs_to_many Accounts Project > has_and_belongs_to_many Companies

I want to get all the companies that are assigned to a given account but are not assigned to a given company

Do you mean assigned to a given account but not assigned to a given project? If so, you could do

account.companies - project.companies

///ark

Yeah my mistake in the initial message, I did mean I wanted companies assigned to a given account but not assigned to a given project.

Thanks for the tip, I see that this does two queries so it could become a bit of a performance issue, but for now it's a lot nicer than my custom query in the model.

Cheers,

-D