Frederick Cheung wrote:

>> Why does only the first object in the collection
>> have a different object_id, and why does this
>> difference go away if the empty a.steps is loaded
>> before b is added?  Is it a proxy thing?
>>
> Because .first will hit the database and load a fresh copy (if the
> collection is not already loaded). I waffled about this a bit a while
> ago: http://www.spacevatican.org/2008/11/15/first-foremost-and-0

Thanks Fred for pointing out the new behaviour of
"first" and "last".

However that's not the problem here. You get the same
behaviour if you use steps[0].

Looking at it again after some sleep, I see that the
different b object is actually loaded at the "a.steps << b"
line. That is, the object is added by updating the foreign key
in the database, loading the collection, then folding in any
new_records, which ends up giving you the different b from
the database.

The association_collection << method could easily be changed
to respect the identity of objects being added to a collection.
Should this be done to respect the POLS, violated for the OP?

-- 
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to