What is the difference between
parent.children << child.new
and
parent.children.build(params[:child])
What is the difference between
parent.children << child.new
and
parent.children.build(params[:child])
In the first one, the child is saved right away. In the second, the child is not saved until the parent is saved
You may find this usefull: http://blog.mrbrdo.net/2009/10/27/ruby-on-rails-new-vs-create-vs-build/
Sharagoz wrote:
In the first one, the child is saved right away. In the second, the child is not saved until the parent is saved
You may find this usefull: http://blog.mrbrdo.net/2009/10/27/ruby-on-rails-new-vs-create-vs-build/
Thanks Sharagoz. I got some idea about this.
Actually if the parent is not persisted, the shovel operator does not save data on db.