activerecord - How to query nested associations in rails -
my models campaign.rb
has_many: views_logs
user.rb
has_many :views_logs
views_log.rb
belongs_to :campaign belongs_to :user
i want campaign.first.views_logs.uniq.users.genders
know query wrong want this
you need define direct relationship through parameter:
class modelname has_many :views_logs has_many :users through: :views_logs end
then can query this: model_name.user.where(gender: 'male')
Comments
Post a Comment