Adding associations without commiting to database

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 changes

and 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.

For that, they use:

p.reload and/or p.tags.reload

The tag is saved when you save p (provided you have :autosave => true
set)
That’s shown here:

under the examples.

RTFS, and use backdoors :slight_smile:

Post.first.tags.target << Tag.first