Smarter Eager Loading?

Question... if i've got a one-to-one relationship between Assets and Tags (simple example), and I do:

a = Asset.find 1, :include => :tag

I can do "a.tag" without hitting the database again. But "a.tag.asset" instantiates a new Asset object, with a new database query... even though it's a reference back to the original object. Now I've got two instances of the same object, which could be confusing.

Is there a way to make ActiveRecord "smart" enough to know that an instance of a given record is already initialized?

Thanks,

Norman

Without hacking the source code I would think not.

ActiveRecord would usually do some caching in situations like this, but because your initial query is :include => “tag”, that goes out the window.

Without hacking the source code I would think not.

ActiveRecord would usually do some caching in situations like this,
but because your initial query is :include => "tag", that goes out
the window.

I believe http://svn.techno-weenie.net/projects/plugins/active_record_context/   solves this problem because it caches loaded records by id (rather
than caching the results of an sql query, keyed by that query).
Fundamentally it would be nice if rails knew which the 'reverse'
association was, but right now that's not the case.

Fred