Skip to content
This repository has been archived by the owner on Feb 9, 2019. It is now read-only.

Question: heritage and ActiveRecord associations #15

Open
hagitgit opened this issue Mar 4, 2013 · 1 comment
Open

Question: heritage and ActiveRecord associations #15

hagitgit opened this issue Mar 4, 2013 · 1 comment

Comments

@hagitgit
Copy link

hagitgit commented Mar 4, 2013

Hi,

Thanks for the great gem.

I couldn't figure out how to implement associations when the type of the heir is unknown.
Example: I want to do something like:

class Post < ActiveRecord::Base
  acts_as_predecessor
  belongs_to :site
end

class BlogPost < ActiveRecord::Base
  acts_as_heir_of :post
end

class ImagePost < ActiveRecord::Base
  acts_as_heir_of :post
end

class Site < ActiveRecord::Base
  has_many :posts #could be BlogPost or ImagePost 

  def create_some_posts
      post1 = BlogPost.create
      posts << post1
      post2 = ImagePost.create
      posts << post2
  end
end

How should I fix this code? Please advise. Thanks!

@dipth
Copy link
Owner

dipth commented Jul 22, 2013

@hagits have you tried doing polymorphic associations?
http://guides.rubyonrails.org/v3.2.13/association_basics.html#polymorphic-associations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants