eager loading of @owner in associations

Currently, this is false:

master.slaves.build.master == master

This very short patch in AR solves it: http://gist.github.com/60504

The patch also avoids DB calls in:

master.slaves.first.master

Since it is so simple, what is the reason for not implementing it ?

Gaspard

PS:
Master.has_many :slaves, :class_name => 'Slave'
Slave.belongs_to :master

Hi Gaspard,

That’s a lot simpler than my patch for the same thing, but it doesn’t cover many edge-cases. You can take a look at my patch (and the conversation in the comments) here: http://rails.lighthouseapp.com/projects/8994/tickets/1619

Please join the conversation I’d love to get some more eyeballs and brains thinking about this feature. Regardless of what implementation AR ends up using, I really think it should do something like this.

Cheers,

Murray

Currently, this is false:

master.slaves.build.master == master

This very short patch in AR solves it: http://gist.github.com/60504

The patch also avoids DB calls in:

master.slaves.first.master

Since it is so simple, what is the reason for not implementing it ?

Gaspard

I seem to recall there was a patch for this, derived from the parental
control plugin.
While your change handles the simple case I believe it will mess up
the more complex cases eg if there are two belongs to the same class
you could set the wrong one. I'd also worry that by calling
association= you might end up triggering association callbacks and all
that jazz (or even updates if partial updates is turned off).

Fred