1. 16 8月, 2016 1 次提交
  2. 07 8月, 2016 2 次提交
  3. 17 2月, 2016 1 次提交
    • P
      Fixed `where` for polymorphic associations when passed an array containing different types. · 359adaed
      Philippe Huibonhoa 提交于
      When passing in an array of different types of objects to `where`, it would only take into account the class of the first object in the array.
      
          PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
      	# => SELECT "price_estimates".* FROM "price_estimates"
               WHERE ("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" IN (1, 2))
      
      This is fixed to properly look for any records matching both type and id:
      
          PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
          # => SELECT "price_estimates".* FROM "price_estimates"
               WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1)
               OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
      359adaed
  4. 17 10月, 2015 1 次提交
  5. 16 10月, 2015 1 次提交
  6. 02 10月, 2015 1 次提交
  7. 04 2月, 2015 1 次提交
    • S
      Respect custom primary keys for associations in `Relation#where` · cd0ed12d
      Sean Griffin 提交于
      While we query the proper columns, we go through normal handling for
      converting the value to a primitive which assumes it should use the
      table's primary key. If the association specifies a different value (and
      we know that we're working with an association), we should use the
      custom primary key instead.
      
      Fixes #18813.
      cd0ed12d
  8. 20 1月, 2015 1 次提交
    • S
      Fix bind value copying from subqueried relations · 04d1c371
      Sean Griffin 提交于
      With the old implementation, the bind values were created, and then we
      search the attributes for `Relation` objects, and merge them. This
      completely ignores the order that the actual `where` clause will use. If
      all non-relation where parameters are before the relations, it will
      work. However, if we query on both a relation and a value, with the
      value coming second, it breaks. The order of the hash should not affect
      the final query (especially since hashes being ordered is an
      implementation detail)
      04d1c371
  9. 10 1月, 2015 1 次提交
    • S
      Properly copy nested bind values from subqueried relations · ec475547
      Sean Griffin 提交于
      This is cropping up all over the place. After a brief dive, I'm really
      not sure why we have `arel.bind_values` at all. A cursory grep didn't
      reveal where they're actually being assigned (it's definitely in AR, not
      in Arel). I'd like to dig further into it, as I'm fairly certain we
      don't actually need it, we just need a way for the predicate builder to
      communicate merged binds upstream.
      
      Fixes #18414
      ec475547
  10. 05 12月, 2014 1 次提交
  11. 02 11月, 2014 1 次提交
  12. 07 9月, 2014 1 次提交
    • C
      Fix query with nested array in Active Record · 72d1663b
      Cristian Bica 提交于
      `User.where(id: [[1,2],3])` was equal to `User.where(id:[1, 2, 3])`
      in Rails 4.1.x but because of some refactoring in Arel this stopped
      working in 4.2.0. This fixes it in Rails.
      
      [Dan Olson & Cristian Bica]
      72d1663b
  13. 17 8月, 2014 1 次提交
  14. 14 8月, 2014 1 次提交
  15. 06 7月, 2014 1 次提交
  16. 17 12月, 2013 1 次提交
    • M
      Better support for `where()` conditions that use an association name. · 8062a307
      Martin Emde 提交于
      Using the name of an association in `where` previously worked only
      if the value was a single `ActiveRecrd::Base` object. e.g.
      
          Post.where(author: Author.first)
      
      Any other values, including `nil`, would cause invalid SQL to be
      generated. This change supports arguments in the `where` query
      conditions where the key is a `belongs_to` association name and the
      value is `nil`, an `Array` of `ActiveRecord::Base` objects, or an
      `ActiveRecord::Relation` object.
      
          # Given the Post model
          class Post < ActiveRecord::Base
            belongs_to :author
          end
      
          # nil value finds records where the association is not set
          Post.where(author: nil)
          # SELECT "posts".* FROM "posts" WHERE "posts"."author_id" IS NULL
      
          # Array values find records where the association foreign key
          # matches the ids of the passed ActiveRecord models, resulting
          # in the same query as Post.where(author_id: [1,2])
          authors_array = [Author.find(1), Author.find(2)]
          Post.where(author: authors_array)
      
          # ActiveRecord::Relation values find records using the same
          # query as Post.where(author_id: Author.where(last_name: "Emde"))
          Post.where(author: Author.where(last_name: "Emde"))
      
      Polymorphic `belongs_to` associations will continue to be handled
      appropriately, with the polymorphic `association_type` field added
      to the query to match the base class of the value. This feature
      previously only worked when the value was a single `ActveRecord::Base`.
      
          class Post < ActiveRecord::Base
            belongs_to :author, polymorphic: true
          end
      
          Post.where(author: Author.where(last_name: "Emde"))
          # Generates a query similar to:
          Post.where(author_id: Author.where(last_name: "Emde"), author_type: "Author")
      8062a307
  17. 03 11月, 2013 1 次提交
  18. 27 8月, 2013 1 次提交
  19. 02 5月, 2013 1 次提交
    • G
      Handle aliased attributes in ActiveRecord::Relation. · 54122067
      Godfrey Chan 提交于
      When using symbol keys, ActiveRecord will now translate aliased attribute names to the actual column name used in the database:
      
      With the model
      
        class Topic
          alias_attribute :heading, :title
        end
      
      The call
      
        Topic.where(heading: 'The First Topic')
      
      should yield the same result as
      
        Topic.where(title: 'The First Topic')
      
      This also applies to ActiveRecord::Relation::Calculations calls such as `Model.sum(:aliased)` and `Model.pluck(:aliased)`.
      
      This will not work with SQL fragment strings like `Model.sum('DISTINCT aliased')`.
      
      Github #7839
      
      *Godfrey Chan*
      54122067
  20. 28 2月, 2013 1 次提交
  21. 09 2月, 2013 2 次提交
  22. 08 2月, 2013 2 次提交
  23. 07 2月, 2013 1 次提交
  24. 25 1月, 2013 1 次提交
  25. 09 1月, 2013 3 次提交
  26. 08 1月, 2013 1 次提交
    • A
      * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing... · d99e8c9e
      Aaron Patterson 提交于
      * Strip nils from collections on JSON and XML posts. [CVE-2013-0155] * dealing with empty hashes. Thanks Damien Mathieu
      
      Conflicts:
      	actionpack/CHANGELOG.md
      	actionpack/lib/action_dispatch/http/request.rb
      	actionpack/lib/action_dispatch/middleware/params_parser.rb
      	activerecord/CHANGELOG.md
      	activerecord/lib/active_record/relation/predicate_builder.rb
      	activerecord/test/cases/relation/where_test.rb
      d99e8c9e
  27. 07 12月, 2012 1 次提交
  28. 19 9月, 2012 1 次提交
  29. 13 9月, 2012 1 次提交
    • J
      Fix nested association references · eb4a623d
      Jon Leighton 提交于
      Previously the reflection would be looked up on the wrong class. However
      the test passed because the examples referred back to themselves.
      eb4a623d
  30. 12 9月, 2012 1 次提交
    • B
      Accept belongs_to assoc. keys in ActiveRecord queries · 3da275c4
      beerlington 提交于
      Allows you to specify the model association key in a belongs_to
      relationship instead of the foreign key.
      
      The following queries are now equivalent:
      
      Post.where(:author_id => Author.first)
      Post.where(:author => Author.first)
      
      PriceEstimate.where(:estimate_of_type => 'Treasure', :estimate_of_id => treasure)
      PriceEstimate.where(:estimate_of => treasure)
      3da275c4
  31. 31 5月, 2012 1 次提交