List Info

Thread: Has_many association




Has_many association
user name
2007-01-29 18:48:52
Hello All,
newbie but I have one question:
If I have a Model 'parent' and it contains has_many
associations to 5 
tables.
Now once parent object is loaded, all the other has_many
associated 
model also get retrieved which slows down the 'parent' model
load.
What do you recommend this in these kinds of scenario?
Should disabling has_many option is the only way?
Can we avoid this? what would be the best way?
Thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups-beta.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


Re: Has_many association
user name
2007-01-30 08:00:13
By default the has_many associations are *not* eagerly
loaded along 
with 'parent'.  If you want them eagerly loaded you can
force AR to 
eagerly load the associated model(s) by using an :include
option on 
your find statement:

Parent.find(:first, :conditions=>[...],
:include=>'my_favorite_child')

Doing this generally produces a SQL join so you can make one
trip to 
the DB rather than a series of trips.

On Jan 29, 7:48 pm, "Rails junkie"
<ABoxForTheOtherSt...gmail.com> 
wrote:
> Hello All,
> newbie but I have one question:
> If I have a Model 'parent' and it contains has_many
associations to 5
> tables.
> Now once parent object is loaded, all the other
has_many associated
> model also get retrieved which slows down the 'parent'
model load.
> What do you recommend this in these kinds of scenario?
> Should disabling has_many option is the only way?
> Can we avoid this? what would be the best way?
> Thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails" group.
To post to this group, send email to rubyonrailsgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups-beta.google.com/group/rubyonrails
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )