search for: attributes_of_car

Displaying 1 result from an estimated 1 matches for "attributes_of_car".

2007 May 14
0
building and saving has_many and has_one relations
...''s consider the has_one scenario. Let''s say I have a student who must own exactly one car: class Student has_one(:car) end class Car belongs_to(:student) validates_presence_of(:student_id) end When I do student = Student.new(attributes_of_student) car = student.build_car(attributes_of_car) The car is created, and I can do: student.save! car.save! I don''t understand why build_car also assigns the car to the student. According to the docs [1], build is an equivalent, in this case, for: Car.new("student_id" => student.id, attributes_of_car) which does it assi...