tags:

views:

10

answers:

0

how to organize ORM relationship between the models: Post, Images

Post contains Images as many to many. The post contains a previews of the images (cover).

How to connect the cover

class Post <ActiveRecord:: Base
  has_many: post_image
  has_many: images,: through =>: post_image
end

class Image <ActiveRecord:: Base
  has_many: post_image
  has_many: posts,: through =>: post_image
end

class PostImage <ActiveRecord:: Base
  belongs_to: post
  belongs_to: image
End

class PostCover <ActiveRecord:: Base
  belongs_to: post
  belongs_to: image
end