KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is it possible in Rails to add an association to an existing record without immediately committing this change to the database? E.g. if I have Post has_many :tags post.tags << Tag.first This will commit to database immediately. I've tried other ways instead of <<, but without success (what I want is to create the association when saving the parent object). Is it possible to get behavior like when you are adding association to a new record with build? post.tags.build name: "whatever" I think this is kind of inconsistent in Rails, in some cases it would be useful to have an option to do this. In other words I want post.tags << Tag.first # don't hit the DB here! post.save # hit the DB here!
Tags (comma-separated)
Save Edits
Cancel