RE: Inserting the parent Id to the child table


#1

I’ll probably get flamed for saying this but
@addresses = Address.new(params[:addresses])
@addresses.student_id=@session[“student_id”]

Is what I usually do if I’m associating something to another thing that
already exists.

If I have a student already in the DB, I’m just going to embed the id on
the form or in session and directly add the value just like you did…
In my opinion, (and that’s all it is), why should I create an instance
of a student object (1 extra sql statement to populate the object) when
I already have the ID of the record in my session or in my form? I’ll
save some processing time and just associate it by hand.

If I’m creating the student and address at the same time, then other
methods are more appropriate.