Skip to content

yankforce/polymorphic

Repository files navigation

Objective

demo how to use polymorphic with has_many through at both side

Environment

rails 4.0.0
ruby 1.9.3

Core code relation

class Article < ActiveRecord::Base
  has_many :attachable_entities, as: :entity
  has_many :attachables, through: :attachable_entities, source: :attachable, source_type: Image 
end

class AttachableEntity < ActiveRecord::Base
  belongs_to :entity, polymorphic: true
  belongs_to :attachable, polymorphic: true
end

class Image < ActiveRecord::Base
  has_many :attachable_entities, as: :attachable
  has_many :entities, through: :attachable_entities, source: :entity, source_type: Article 
end

About

show a polymorphic and has_many through

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published