Building a wiki like data model in rails question.

Posted by lillq on Stack Overflow See other posts from Stack Overflow or by lillq
Published on 2010-04-22T05:11:10Z Indexed on 2010/04/22 5:13 UTC
Read the original article Hit count: 259

I have a data model in which I would like to have an item that has a description that can be edited. I would like to also keep track of all edits to the item. I am running into issues with my current strategy, which is:

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

Can the Item have multiple associations to the same class like this?

I was thinking that I should switch to keeping track of the edit version in the Edit object and then just sorting the has_many relationship base on this version.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord