Re: After loading model, can it be again accessed withoutSQL...

Ball, Donald A Jr \(Library\)
Mon, 16 Apr 2007 22:07:39 -0000

> from what i know that''s no problem at all ?!? that''s the
> whole point of eager loading....
>
> @user = User.find(:first, include => [:accounts])
>
> @user.accounts.find(blablaba-)
> @user.accounts.each do { |account| blablabla } @user.accounts.count
>
> these and more will workwithout re-querying the database.
> basically any AR method you use on @user.accounts won''t hit
> the database, except for updating/adding/removing an account,
> of course.

My understand was that he was trying to query the eagerly loaded user''s
accounts using SQL conditions, which AFAIK you cannot do without
requerying the database. Sure, you can iterate through and find the
account named ''Checking Account'', but it''s probably
faster to have the
database do the work for you.

For a handful of accounts and a simple criteria like this, it''s almost
certainly 6 == 1/2 dozen and I''d probably do it all in ruby for
clarity,
but if there are many children and complex criteria, I''d do it in SQL.

- donald

--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com