Polymorphism in Rails

Posted by Newy on Stack Overflow See other posts from Stack Overflow or by Newy
Published on 2010-05-02T19:31:33Z Indexed on 2010/05/02 19:38 UTC
Read the original article Hit count: 136

Filed under:

Say I have two models, Apples and Oranges, and they are both associated with a description in a Text model. Text is a separate class as I'd like to keep track of the different revisions. Is the following correct? Is there a better way to do this?

[Apple]

  has_one :text, :as => :targit, :order => 'id DESC'   
  has_many :revisions, :class_name => 'Text', :as => :targit, :order => 'id', :dependent => :destroy

[Text]

   belongs_to :targit, :polymorphic => true

© Stack Overflow or respective owner

Related posts about ruby-on-rails