# frozen_string_literal: true # == Schema Information # # Table name: post_subscriptions # # post_id :integer not null, primary key # user_id :integer not null # # Indexes # # index_post_subscriptions_on_post_id_and_user_id (post_id,user_id) UNIQUE # index_post_subscriptions_on_user_id (user_id) # # Foreign Keys # # fk_rails_... (post_id => posts.id) # fk_rails_... (user_id => users.id) ON DELETE => cascade ON UPDATE => cascade # class Post::Subscription < ApplicationRecord self.primary_key = :post_id belongs_to :post belongs_to :user validates :user, uniqueness: { scope: [:post_id] } end