Mark Reginald James wrote:
> Frederick Cheung wrote:
> 
>> Even if it were setting it on the in memory object it wouldn't be in  
>> memory object you think it is. Because a was reloaded, the objects in  
>> a.steps are not the objects b & c (although they do correspond to the  
>> same database rows).
> 
> The problem happens before a is reloaded.
> 
> I just did some experiments with puzzling results.
> Would you be able to help explain them Fred?
> 
> Loading development environment (Rails 2.2.2)
>  >> a = Exercise.find(1)
> => #<Exercise id: 1>
>  >> b = Step.new
> => #<Step id: nil, exercise_id: nil>
>  >> b.save
> => true
>  >> c = Step.new
> => #<Step id: nil, exercise_id: nil>
>  >> c.save
> => true
>  >> a.steps << b
> => [#<Step id: 19, exercise_id: 1>]
>  >> a.steps << c
> => [#<Step id: 19, exercise_id: 1>, #<Step id: 20, exercise_id: 1>]
>  >> b.object_id
> => 70254505869500
>  >> a.steps.first.object_id
> => 70254505813160
>  >> c.object_id
> => 70254505838840
>  >> a.steps.last_object_id
> => 70254505838840
> 

Just a WAG, but
a.steps.first.object_id isn't the same reference method as
a.steps.last_object_id

Is the first.object_id creating a new reference to that object, whereas 
last_object_id is returning the reference present in a.steps?

Try the experiment again with the same object referencing method used 
for both first and last.
-- 
Posted via http://www.ruby-forum.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