From our discussion, this is how it should work:
#app/models/image.rb
Class Image < ActiveRecord::Base
has_many :gallery_images
has_many :galleries, through: :gallery_images
has_one :category, through: :gallery_images #-> I think
end
#app/models/gallery.rb
Class Gallery < ActiveRecord::Base
has_many :gallery_images
has_many :images, through: :gallery_images
end
#app/models/gallery_category.rb
Class GalleryImage < ActiveRecord::Base
belongs_to :gallery
belongs_to :image
belongs_to :category
end
#app/models/gallery_category.rb
Class GalleryCategory < ActiveRecord::Base
belongs_to :gallery
has_many :gallery_images
end
Schemas:
images
id | image_info | created_at | updated_at
galleries
id | name | created_at | updated_at
gallery_images
image_id | gallery_id | category_id
gallery_categories
id | gallery_id | name | created_at | updated_at
This might not work out of the box
If you're looking for something simple, you should also consider just adding a type
attribute to your GalleryImages
-
gallery_images
id | gallery_id | image_id | type | created_at | updated_at