Multiple has_many relationships to same model

后端 未结 4 2006
抹茶落季
抹茶落季 2021-02-04 09:07

I have a model User that can create Posts

User
 has_many :posts
Post
 belongs_to :user

However, I want to also allow users to save posts as boo

4条回答
  •  不思量自难忘°
    2021-02-04 09:12

    I did something similar to previous comments here but successfully used inverse_of to differentiate users and 'post authors':

    User
    has_many :authored_posts, class_name: 'Post', inverse_of: 'author'
    

提交回复
热议问题