Add association (<<) without committing to database

前端 未结 4 914
挽巷
挽巷 2021-02-05 04:21

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 :ta

4条回答
  •  野性不改
    2021-02-05 05:06

    post_tag = post.post_tags.find_or_initialize_by_tag_id(Tag.first.id)
    post_tag.save
    

提交回复
热议问题