我有以下模型和它们之间的关系:
App
has_many :subscriptions
has_many :users, through: :subscriptions
User
belongs_to :app
has_many :subscriptions, :dependent => :destroy
Subscription
belongs_to :user
belongs_to :app
# Table name: subscriptions
#
# app_id :integer
# id :integer not null, primary key
# user_id :integer
# approved :boolean
#
# Table name: apps
#
# id :integer not null, primary key
# name :string(255)
# user_id :integer
# private :boolean
#
# Table name: users
#
# app_id :integer
# id :integer not null, primary key
我想仅显示已订阅的已批准订阅或公共应用程序(其中private
为 false)。
# user.rb < this is only for approved but how to add here also public subscribed apps
def approved_or_public_subscriptions
subscriptions.where(approved: true)
end