开发者

belongs_to_many userstamps in Rails

开发者 https://www.devze.com 2023-02-19 10:43 出处:网络
Im tryign to update a model of mine so that it will have a created_by and updated_by field. Looking into some questions and answers here, it seems I don\'t have the same problem as them.

Im tryign to update a model of mine so that it will have a created_by and updated_by field. Looking into some questions and answers here, it seems I don't have the same problem as them.

My TestCase model should have a created_by and updated_by foreign key, but it should both be a User class. Is that possible?

something like:

belongs_to :user, :foreign_key => 'created_by'
belongs_to :user, :foreign_key => 'updated_by'

Keep in mind that created by and updated_by can 开发者_如何学JAVAbe different(meaning another user can edit the testcase)


Try to use:

belongs_to :creator, :class_name => "User", :foreign_key => 'created_by'
belongs_to :updater, :class_name => "User", :foreign_key => 'updated_by'

You should refer to that objects through:

item.creator
item.updater
0

精彩评论

暂无评论...
验证码 换一张
取 消