John Russell
2006-Apr-20 19:56 UTC
[Rails] multi level :includes for preloading objects from database
I am using :include => :assocation to preload data that I know will be used later in the UI over and over. However I have data like that that is an association of one of the associations. How would i preload that data too? e.g. grant has_many :people and person belongs_to :group I can''t include the :group association in a Grant.find because its not an association of grant, but I use grant.person.group all over the place so it hits the db every time. How can I include group in the Grant.find? thanks. -- Posted via http://www.ruby-forum.com/.
Wilson Bilkovich
2006-Apr-20 20:01 UTC
[Rails] multi level :includes for preloading objects from database
On 4/20/06, John Russell <jjrussell@gmail.com> wrote:> I am using :include => :assocation to preload data that I know will be > used later in the UI over and over. However I have data like that that > is an association of one of the associations. How would i preload that > data too? > > e.g. > > grant has_many :people > > and > > person belongs_to :group > > I can''t include the :group association in a Grant.find because its not > an association of grant, but I use grant.person.group all over the place > so it hits the db every time. How can I include group in the > Grant.find? > > thanks. >You can nest the include statements, as of Rails 1.1: :include => [:grants, {:people => :groups}] --Wilson.