Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate where.not working as NOR and will be changed to NAND in Rails 6.1 #36029

Merged
merged 1 commit into from
Apr 23, 2019

Commits on Apr 19, 2019

  1. Deprecate where.not working as NOR and will be changed to NAND in R…

    …ails 6.1
    
    `where.not` with polymorphic association is partly fixed incidentally at
    213796f (refer rails#33493, rails#26207, rails#17010, rails#16983, rails#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 rails#31209.
    kamipo committed Apr 19, 2019
    Configuration menu
    Copy the full SHA
    12a9664 View commit details
    Browse the repository at this point in the history