# frozen_string_literal: true # == Schema Information # # Table name: gallery_interactions # # id :integer not null, primary key # position :integer not null # gallery_id :integer not null # post_id :integer not null # # Indexes # # index_gallery_interactions_on_gallery_id (gallery_id) # index_gallery_interactions_on_position (position) # index_gallery_interactions_on_post_id (post_id) # # Foreign Keys # # fk_rails_... (gallery_id => galleries.id) ON DELETE => cascade ON UPDATE => cascade # fk_rails_... (post_id => posts.id) # class GalleryInteraction < ApplicationRecord belongs_to :post belongs_to :gallery, counter_cache: :image_count def image_index { id: gallery_id, position: position } end def as_json(*) image_index end end