Krassimir Todorov
2006-Jul-24 12:51 UTC
[Rails] HowTo?: Eager caching of third order ActiveRecord assoc.
Hello. Using the ":include", which generates a "LEFT OUTER JOIN" SQL command, it is possible to eagerly preload second order data objects (children) for a given association. I wanted to know, if it is possible to eagerly preload and cache third order (or more) data objects, which are little-children or little-little-children. As I''ve seen. it is possible to add "LEFT OUTER JOIN" SQL clauses with the needed conditions, to fetch little-little-children data, but how to do this with ActiveRecord and its cache? My models are as follow: # Model Software # ----------------------------- class Software < ActiveRecord::Base has_many :releases, :exclusively_dependent => true end # Model Release # ----------------------------- class Release < ActiveRecord::Base belongs_to :software has_many :acquisitions, :exclusively_dependent => true end # Model Acquisition # ----------------------------- class Acquisition < ActiveRecord::Base belongs_to :release has_and_belongs_to_many :languages end # Model Language # ----------------------------- class Language < ActiveRecord::Base has_and_belongs_to_many :acquisitions end Is it possible to find(), or paginate() Software-s, while eagerly preloading in cache their Release-s, the release Acquisition-s, and the supported Language-s for those releases? And how to do it? Thank to all for your suggestions. -- Posted via http://www.ruby-forum.com/.
Kevin Olbrich
2006-Jul-24 13:42 UTC
[Rails] HowTo?: Eager caching of third order ActiveRecord assoc.
On Monday, July 24, 2006, at 2:50 PM, Krassimir Todorov wrote:>Hello. > >Using the ":include", which generates a "LEFT OUTER JOIN" SQL command, >it is possible to eagerly preload second order data objects (children) >for a given association. > >I wanted to know, if it is possible to eagerly preload and cache >third order (or more) data objects, which are little-children or >little-little-children. As I''ve seen. it is possible to add >"LEFT OUTER JOIN" SQL clauses with the needed conditions, >to fetch little-little-children data, but how to do this with >ActiveRecord and its cache? > >My models are as follow: > > # Model Software > # ----------------------------- > class Software < ActiveRecord::Base > has_many :releases, :exclusively_dependent => true > end > > # Model Release > # ----------------------------- > class Release < ActiveRecord::Base > belongs_to :software > has_many :acquisitions, :exclusively_dependent => true > end > > # Model Acquisition > # ----------------------------- > class Acquisition < ActiveRecord::Base > belongs_to :release > has_and_belongs_to_many :languages > end > > # Model Language > # ----------------------------- > class Language < ActiveRecord::Base > has_and_belongs_to_many :acquisitions > end > >Is it possible to find(), or paginate() Software-s, while >eagerly preloading in cache their Release-s, the release >Acquisition-s, and the supported Language-s for those releases? >And how to do it? > >Thank to all for your suggestions. > > > >-- >Posted via http://www.ruby-forum.com/. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsTry this.. Software.find(:all, :include=>{:releases=>{:aquisitions=>:languages}}) In theory this should work, but YMMV. _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Krassimir Todorov
2006-Jul-24 14:02 UTC
[Rails] Re: HowTo?: Eager caching of third order ActiveRecord assoc.
Kevin Olbrich wrote:> On Monday, July 24, 2006, at 2:50 PM, Krassimir Todorov wrote: >>to fetch little-little-children data, but how to do this with >> # Model Release >> has_and_belongs_to_many :languages >>Acquisition-s, and the supported Language-s for those releases? >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails > > Try this.. > > Software.find(:all, :include=>{:releases=>{:aquisitions=>:languages}}) > > In theory this should work, but YMMV. > > _Kevin > www.sciwerks.comGREAT ... IT WORKS ... Thank you very much! -- Posted via http://www.ruby-forum.com/.
Krassimir Todorov
2006-Jul-24 14:20 UTC
[Rails] Re: HowTo?: Eager caching of third order ActiveRecord assoc.
The result is OK, and retreived data is really cached. Thank you again, Kevin! Krassimir Todorov wrote:> Kevin Olbrich wrote: >> On Monday, July 24, 2006, at 2:50 PM, Krassimir Todorov wrote: >>>to fetch little-little-children data, but how to do this with >>> # Model Release >>> has_and_belongs_to_many :languages >>>Acquisition-s, and the supported Language-s for those releases? >>>Rails@lists.rubyonrails.org >>>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> Try this.. >> >> Software.find(:all, :include=>{:releases=>{:aquisitions=>:languages}}) >> >> In theory this should work, but YMMV. >> >> _Kevin >> www.sciwerks.com > > GREAT ... IT WORKS ... > > Thank you very much!-- Posted via http://www.ruby-forum.com/.