Answer the question
In order to leave comments, you need to log in
Scope conflict when joining one table, what to do?
In the model of tasks with users, there are 2 connections.
belongs_to :initiator, :class_name => 'User', :foreign_key => 'initiator_id'
belongs_to :designer, :class_name => 'User', :foreign_key => 'designer_id'
scope :initiator_filter, ->(name){ joins(:initiator).where("users.name LIKE ?", "%#{name}%") unless name.nil? }
scope :designer_filter, ->(name){ joins(:designer).where("users.name LIKE ?", "%#{name}%") unless name.nil? }
Answer the question
In order to leave comments, you need to log in
joins('users initiators on initiators.id = initiator_id').where('initiators.name LIKE ...')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question