I'm not sure how the has_one relationship is translating for scopes,
but here is an example that causes problems:
Task.joins(:client).where('clients.name' => 'test')
results in the following SQL:
SELECT `tasks`.* FROM `tasks` INNER JOIN `projects` ON `tasks`.`id` IS
NULL INNER JOIN `clients` ON `clients`.`id` = `projects`.`client_id`
WHERE (`clients`.`name` = 'test')
I realize I can do Task.joins(:project => :client), but that is what I
am trying to avoid for my complicated scopes.
Thanks,
Tom
On Nov 5, 1:39 pm, Erol Fornoles <[email protected]> wrote:
> On Sat, Nov 6, 2010 at 1:13 AM, TomRossi7 <[email protected]> wrote:
> > Why is belongs_to :through not an option with Rails? I'm sure there
> > is something I'm missing! I find myself wanting it more now with lazy
> > loading in Rails 3.
>
> > project belongs_to client
>
> > task belongs_to project
> > task belongs_to client :through project
>
> > I can work around it by just creating a method on the task model
> > called client and just returns project.client, but that isn't as
> > beautiful!
>
> > Thanks,
> > Tom
>
> What you're really looking for is has_one :through.
>
> --
> Erol M.
> Fornoleshttp://github.com/Erolhttp://twitter.com/erolfornoleshttp://ph.linkedin.com/in/erolfornoles
--
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.