Ruby on Rails Monday, December 13, 2010

I am still trying to wrap my head around FG... can someone explain me why I am seemingly having to reload an object to have access to the correct association value which I updated since creating the object with FG. Here is an example (Factory below also):

@person = Factory(:person)
@person.addresses.size.should == 0
address = Factory(:address)
@person.add_address(address)
@person = Person.find(@person.id)   # if I dont do this I get the old value, 0, but if I reload I get the right value, 1.
@person.addresses.size.should == 1
@person.addresses[0].person_id.should == @person.id


Factory.define :person do |f|
  f.first_name {"MyString"}
  f.middle_name {"MyString"}
  f.last_name {"MyString"}
end

Factory.define :address do |f|
  f.person_id {1}
  f.address {"MyString"}
  f.zip {"94587"}
  f.city {"MyString"}
  f.state {"MyString"}
end

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment