activerecord - Rails: any way to preload (include) parent association -


i have rails 2.3 app following models.

class message << ar::base   has_many :message_copies end   class messagecopy << ar::base   belongs_to :message end 

whenever query messagecopy, need reference parent message's attributes. end pre-loading (via :include => :message) reduce # of db queries.

so far came this:

named_scope :with_parent_msg, :include => :message 

this allows me this:

@user.message_copies.with_parent_msg 

is there better way this? don't have call with_parent_msg?

open suggestions. thanks!

you can define default_scope this

class messagecopy << ar::base   belongs_to :message   default_scope include(:message) end 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -