activerecord记录不处于:通过状态
我需要得到的记录不在:通过条件 我有三张桌子:activerecord记录不处于:通过状态,activerecord,Activerecord,我需要得到的记录不在:通过条件 我有三张桌子: class A < ActiveRecord::Base has_many :B_A has_many :B, through: :B_A end class B < ActiveRecord::Base has_many :B_A has_many :A, through: :B_A end class BA < ActiveRecord::Base belongs_to :A belongs_to :B
class A < ActiveRecord::Base
has_many :B_A
has_many :B, through: :B_A
end
class B < ActiveRecord::Base
has_many :B_A
has_many :A, through: :B_A
end
class BA < ActiveRecord::Base
belongs_to :A
belongs_to :B
end
class A
我通过
listOfA=B.A
将所有A链接到一个特定的B,但我还需要将所有A都链接到任何B中。我该怎么做?好的,我在我的连接查询中有两个条件。
我的MySql是:
select a.`id`, a.`label`
from `A` a
left join `BA` ba
on a.`id` = ba.`a`
where a.`uid`='userId'
and ba.`a` is null
我现在的activeRecord是:
A.select(['A.id', :label])
.joins('left outer join B_A on B_A.a_id = A.id')
.where({ user_id: current_user.id, "B_A.a_id" => nil })
我所有的A都不在BA