Answers for "rails has_many through source 2"

0

rails has_many through source 2

class User
  has_many :subscriptions
  has_many :newsletters, :through => :subscriptions
end

class Newsletter
  has_many :subscriptions
  has_many :users, :through => :subscriptions
end

class Subscription
  belongs_to :newsletter
  belongs_to :user
end

class Newsletter
  has_many :subscriptions
  has_many :subscribers, :through => :subscriptions, :source => :user
end
Posted by: Guest on March-24-2022

Code answers related to "rails has_many through source 2"

Browse Popular Code Answers by Language