Ruby on rails 在rails问题中构建类似wiki的数据模型
我有一个数据模型,其中我希望有一个具有可编辑描述的项。我还想跟踪对该项目的所有编辑。我目前的战略遇到了问题,即:Ruby on rails 在rails问题中构建类似wiki的数据模型,ruby-on-rails,database-design,activerecord,Ruby On Rails,Database Design,Activerecord,我有一个数据模型,其中我希望有一个具有可编辑描述的项。我还想跟踪对该项目的所有编辑。我目前的战略遇到了问题,即: class Item < ActiveRecord::Base has_one :current_edit, :class_name => "Edit", :foreign_key => "current_edit_id" has_many :edits end class Edit < ActiveRe
class Item < ActiveRecord::Base
has_one :current_edit,
:class_name => "Edit",
:foreign_key => "current_edit_id"
has_many :edits
end
class Edit < ActiveRecord::Base
belongs_to :item
end
class项“编辑”,
:foreign\u key=>“当前\u编辑\u id”
有很多:编辑
结束
类编辑
该项是否可以像这样与同一类有多个关联
我在想,我应该切换到在编辑对象中跟踪编辑版本,然后根据这个版本对
有很多关系进行排序。是的,它可以。但是你必须使用属于
而不是拥有一个
。然后,您的模型必须看起来像:
(Item, current_edit_id, ...)
(Edit, item_id, ....)
rails文档对此进行了更详细的解释:是的,它可以。但是你必须使用属于
而不是拥有一个
。然后,您的模型必须看起来像:
(Item, current_edit_id, ...)
(Edit, item_id, ....)
rails文档对此进行了更详细的解释: