DEfusion
2007-Dec-13 19:19 UTC
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Wilden
2007-Dec-13 21:13 UTC
Re: Am I trying to do something silly here, as I can''t figure out the best way to do it.
> 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 companyDo you mean assigned to a given account but not assigned to a given project? If so, you could do account.companies - project.companies ///ark --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
DEfusion
2007-Dec-13 22:00 UTC
Re: Am I trying to do something silly here, as I can''t figure out the best way to do it.
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---