I have a Rails 2.3 application with the following models.
class Message << AR::Base
has_many :message_copies
end
class MessageCopy << AR::Base
belongs_to :message
end
Whenever I request MessageCopy, I always need to refer to the attributes of the parent messages. So I always get preload (via: include =>: message) to reduce the number of db requests.
So far I have come up with this:
named_scope :with_parent_msg, :include => :message
This allows me to easily do this:
@user.message_copies.with_parent_msg
Is there a better way to do this? So I donβt need to always call with_parent_msg?
Open all offers. Thank!
source
share