belongs_to and has_many to the same model

后端 未结 1 1984
借酒劲吻你
借酒劲吻你 2020-12-16 15:53

I am wondering whether there is a way to do this with rails or not. Basically I have a user model and an event model. Event is created by a user and I want to have a foreign

相关标签:
1条回答
  • 2020-12-16 16:16

    Simply pass some options to belongs_to:

    belongs_to :creator, :class_name => "User", :foreign_key => "user_id"
    

    This specifies that the creator method will be a User object, referencing the user_id field.

    0 讨论(0)
提交回复
热议问题