This project is archived and is in readonly mode.
has_one through associations not saved correctly
-
gerad
Also happens on 2.3.4 version 7ba80252a5a6bd94c8445347caee663b12c1a526
-
Jigar Patel
Three cases -
1. p = Person.new
c = Club.new p.club = c This line will insert a new row in memberships table with both person_id and club_id as nil.
c.save p.save Both objects will be saved without any related membership. Hence your test case fails.- p = Person.new
c = Club.new c.save p.club = c
This will create an entry in Membership table with club_id = "c.id" and person_id as nil
p.save will save the object but without any related membership and hence without any related organization.- p = Person.new
p.save p will be a Person with some id.
c = Club.new c.save c will be a Club with some id.
p.club = c This will create an entry in memberships table with person_id and club_id pointing to corresponding rows in persons and clubs tables.
p.save will save and you will be able to fetch club.
- p = Person.new
-
lakshmanan
I ran your testcase statements in console and I test Membership after every statement. You are not saving anything
In short -> you are playing in memory without saving anything. so literally you are playing with nils
>> p = Person.new => #<Person id: nil, created_at: nil, updated_at: nil> >> Membership.last => nil >> c = Club.new => #<Club id: nil, created_at: nil, updated_at: nil> >> Membership.last => nil >> p.club = c => #<Club id: nil, created_at: nil, updated_at: nil> >> Membership.last => nil >> c.save! => true >> Membership.last => nil >> c.reload => #<Club id: 2, created_at: "2010-07-24 11:57:24", updated_at: "2010-07-24 11:57:24"> >> p.save! # after this statement - your test will pass => true >> Membership.last => #<Membership id: 2, club_id: nil, person_id: 2, created_at: "2010-07-24 11:57:43", updated_at: "2010-07-24 11:57:43">Hope it helps
-
Rohit Arondekar
- State changed from new to invalid
- Importance changed from to Low
p.clubandcare not the same.cis created whencis saved. Whilep.clubis created whenpis saved.