提交 1cea9741 编写于 作者: R Ryuta Kamizono

Merge pull request #37359 from kamipo/maintain_extra_joins

Maintain extra joins for string or complex arel conditions
上级 e98d68af
......@@ -36,7 +36,7 @@ def join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
nodes = arel.constraints.first
others, children = nodes.children.partition do |node|
fetch_arel_attribute(node) { |attr| attr.relation.name != table.name }
!fetch_arel_attribute(node) { |attr| attr.relation.name == table.name }
end
nodes = table.create_and(children)
......
......@@ -3,6 +3,6 @@
class Rating < ActiveRecord::Base
belongs_to :comment
has_many :taggings, as: :taggable
has_many :taggings_without_tag, -> { left_joins(:tag).where("tags.id": nil) }, as: :taggable, class_name: "Tagging"
has_many :taggings_without_tag, -> { left_joins(:tag).where("tags.id": [nil, 0]) }, as: :taggable, class_name: "Tagging"
has_many :taggings_with_no_tag, -> { joins("LEFT OUTER JOIN tags ON tags.id = taggings.tag_id").where("tags.id": nil) }, as: :taggable, class_name: "Tagging"
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册