Epoch
unread,Aug 22, 2011, 2:29:02 AM8/22/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby or Rails Oceania
Hi guys,
ActiveRecord in rails3 has a nice improvement where most of the API
returns a ActiveRecord::Relation so you can chain things together.
> Asset.where(:project_id => 1).class => ActiveRecord::Relation
One exception at the moment when using an association, it returns an
Array:
class Project
has_many :assets
end
> Project.first.assets.class => Array
The problem with this is we lose chain-ability, which means I can't do
things like this:
> @project = Project.first
> @project.assets.where(:active => true)
though I can get the same thing with something like this
> Asset.where(:project_id => 1, :active => true)
Personally I prefer lazy loading and chaining and was wondering if
it's possible with associations, or am I missing something, any
thoughts?
Daniel