1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #37359 from kamipo/maintain_extra_joins

Maintain extra joins for string or complex arel conditions
This commit is contained in:
Ryuta Kamizono 2019-10-04 15:46:39 +09:00 committed by GitHub
commit 686002085a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View file

@ -37,7 +37,7 @@ module ActiveRecord
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)

View file

@ -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