提交 65dba0a1 编写于 作者: R Ryuta Kamizono

Merge pull request #37359 from kamipo/maintain_extra_joins

Maintain extra joins for string or complex arel conditions
上级 41326660
......@@ -37,7 +37,7 @@ def join_constraints(foreign_table, foreign_klass, join_type, alias_tracker)
nodes = arel.constraints.first
others = nodes.children.extract! do |node|
Arel.fetch_attribute(node) { |attr| attr.relation.name != table.name }
!Arel.fetch_attribute(node) { |attr| attr.relation.name == table.name }
end
joins << table.create_join(table, table.create_on(nodes), join_type)
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册