Hey all,
So there are a couple features that my team would find useful in
ActiveRecord, that I can volunteer our time to work on. I mainly want
to see if there's going to be support in the Rails core team to these
changes into core before doing a full dev cycle on them.
Please let me know if you support these ideas. If so, my team can work
on implementing them.
1) Eager association loading
Currently, if you have a model like this:
class Forum < AR
has_many :posts
end
class Post < AR
belongs_to :forum
end
Then walk thru these records:
<% for forum in @forums %>
Title: <%= forum.post.subject %>
<% end %>
Currently, this will do an extra SQL select * from post for each loop.
DataMapper (datamapper.org) has an interesting approach: The first
time that a sub-association is loaded, then all associations are
preloaded, since most times you're in a loop (as above). While
the :include option helps with this somewhat, when passing collection
objects around, you often don't know how the associations are going to
be used.
2) Optimized updates
Currently, if one attribute is changed in an AR model, then the entire
model is parsed and sent as an UPDATE statement. This is not really
desirable from a network or database standpoint.
There are already some counters in AR for monitoring changes. Is
there a per-attribute @changed data structure? It seems like this
could just be set to true when updating a column. Then, on save, only
those with the @changed flag are actually converted to SQL.
These are changes we really need for our local copy anyways.
Thoughts?
Thanks,
Nate