diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-25 14:22:16 -0400 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-25 14:22:16 -0400 |
commit | ea6139101ccaf8be03b536b1293a9f36bc12f2f7 (patch) | |
tree | ea5bcf710af3e6b84fa55e8e3d1a3ded6005e594 /activerecord/test | |
parent | c146065b8df8b3893b9ae33111987d5f1c18d457 (diff) | |
download | rails-ea6139101ccaf8be03b536b1293a9f36bc12f2f7.tar.gz rails-ea6139101ccaf8be03b536b1293a9f36bc12f2f7.tar.bz2 rails-ea6139101ccaf8be03b536b1293a9f36bc12f2f7.zip |
Allow `Relation#or` to accept a relation with different `references`
Note that the two relations must still have the same `includes` values
(which is the only time `references` actually does anything). It makes
sense for us to allow this, as `references` is called implicitly when
passing a hash to `where`.
Fixes #29411
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relation/or_test.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/or_test.rb b/activerecord/test/cases/relation/or_test.rb index 3269620987..b01801b41f 100644 --- a/activerecord/test/cases/relation/or_test.rb +++ b/activerecord/test/cases/relation/or_test.rb @@ -1,11 +1,14 @@ # frozen_string_literal: true require "cases/helper" +require "models/author" +require "models/categorization" require "models/post" module ActiveRecord class OrTest < ActiveRecord::TestCase fixtures :posts + fixtures :authors def test_or_with_relation expected = Post.where("id = 1 or id = 2").to_a @@ -115,5 +118,13 @@ module ActiveRecord Post.where(id: [1, 2, 3]).or(title: "Rails") end end + + def test_or_with_references_inequality + joined = Post.includes(:author) + actual = joined.where(authors: { id: 1 }) + .or(joined.where(title: "I don't have any comments")) + expected = Author.find(1).posts + Post.where(title: "I don't have any comments") + assert_equal expected.sort_by(&:id), actual.sort_by(&:id) + end end end |