On Jun 8, 5:18 am, Scott Holland <[email protected]>
wrote:
> Hello!
>
> I want to limit my model to just show companies from the current users
> account:
>
> user.account.companies
>
> I have this in my model which seems to be working:
>
> def self.find(*args)
> args << {:conditions => XXXXX"}
> super
> end
>
I would question the wisdom of doing that - it may work in the short
term, but you may find it breaks other stuff.
> Now I just need to turn this sql into rails conditions:
>
> SELECT `companies`.* FROM `companies` INNER JOIN `users` ON
> `companies`.user_id = `users`.id WHERE ((`users`.account_id = 1))
>
Take a look at the :joins option to find (if you have the associations
right you don't even need to write out the join clause in full,
specifying the name of the association is enough).
In this case though I'm not sure why you wouldn't just do
some_user.account.companies; you'd get back the same result set.
Fred
> Can anyone help with this?
>
> Thanks
>
> Scott
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---