On 2006-07-27, at 11:56 , Josh Susser wrote:
That's a valid point. But did you read Jonathan's patch? It covers that case where you're dealing with new records just fine. I think the issue he was correcting was that has_one *always* saves the child object, not just for new records.

Strictly, it does not *always* save the child, only if it's been *loaded*.

It checks the association ivar directly, meaning it does not go through the accessor, and therefore does not try to load it.

Saving loaded associations is a cheap way to make sure you save everytime a change *could have* happened. Without a dirtyness check, I'd say that's good enough.

The alternative would be a handcoded dirtyness check, something like:

  assoc_record.class.find(record.id).attributes.all? { |(k, v)|
    assoc_record.send(k) == v }

Which quickly becomes expansive.

_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to