diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-09 23:25:30 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-19 13:49:31 +0900 |
commit | 12a9664ff60f0e2712fd1f79f8dbec06e2f004a2 (patch) | |
tree | 1a45630ea34f3c2fee7f1b3be1ffb9d894c9f442 /activerecord/lib/rails | |
parent | 16dae7684edc480ee3fe65dfff8e19989402c987 (diff) | |
download | rails-12a9664ff60f0e2712fd1f79f8dbec06e2f004a2.tar.gz rails-12a9664ff60f0e2712fd1f79f8dbec06e2f004a2.tar.bz2 rails-12a9664ff60f0e2712fd1f79f8dbec06e2f004a2.zip |
Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1
`where.not` with polymorphic association is partly fixed incidentally at
213796f (refer #33493, #26207, #17010, #16983, #14161), and I've added
test case e9ba12f to avoid lose that fix accidentally in the future.
In Rails 5.2, `where.not(polymorphic: object)` works as expected as
NAND, but `where.not(polymorphic_type: object.class.polymorphic_name,
polymorphic_id: object.id)` still unexpectedly works as NOR.
To will make `where.not` working desiredly as NAND in Rails 6.1, this
deprecates `where.not` working as NOR. If people want to continue NOR
conditions, we'd encourage to them to `where.not` each conditions
manually.
```ruby
all = [treasures(:diamond), treasures(:sapphire), cars(:honda), treasures(:sapphire)]
assert_equal all, PriceEstimate.all.map(&:estimate_of)
```
In Rails 6.0:
```ruby
sapphire = treasures(:sapphire)
nor = all.reject { |e|
e.estimate_of_type == sapphire.class.polymorphic_name
}.reject { |e|
e.estimate_of_id == sapphire.id
}
assert_equal [cars(:honda)], nor
without_sapphire = PriceEstimate.where.not(
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
)
assert_equal nor, without_sapphire.map(&:estimate_of)
```
In Rails 6.1:
```ruby
sapphire = treasures(:sapphire)
nand = all - [sapphire]
assert_equal [treasures(:diamond), cars(:honda)], nand
without_sapphire = PriceEstimate.where.not(
estimate_of_type: sapphire.class.polymorphic_name, estimate_of_id: sapphire.id
)
assert_equal nand, without_sapphire.map(&:estimate_of)
```
Resolves #31209.
Diffstat (limited to 'activerecord/lib/rails')
0 files changed, 0 insertions, 0 deletions