I think there is a slight inconsistency in Rails regarding adding
associations between existing records.
Assume Post has_many :tags.
We have an analogy when we want to immediately add the association to
either new or existing child:
Post.first.tags.create name: “my tag” # commits immediately
and to existing tag
Post.first.tags << Tag.first # commits immediately
But we don’t have an analogy to build:
p = Post.first
p.tags.build name: “my tag”
p.save # commits all changesand to existing tag
?
I think this is unfortunate, because I like the idea of building all
changes in memory first and then commiting everything together. I have a
project where this would be useful for me, but is currently not
possible.
Why not? Discuss.
