1. 26 6月, 2014 1 次提交
    • S
      Deprecate automatic counter caches on has_many :through · d730e374
      Sean Griffin 提交于
      Reliant on https://github.com/rails/rails/pull/15747 but pulled to a
      separate PR to reduce noise. `has_many :through` associations have the
      undocumented behavior of automatically detecting counter caches.
      However, the way in which it does so is inconsistent with counter caches
      everywhere else, and doesn't actually work consistently.
      
      As with normal `has_many` associations, the user should specify the
      counter cache on the `belongs_to`, if they'd like it updated.
      d730e374
  2. 10 6月, 2014 2 次提交
  3. 14 3月, 2014 3 次提交
  4. 10 3月, 2014 3 次提交
  5. 04 3月, 2014 1 次提交
    • M
      Make exists? use bound values. · f317cc8b
      Martin Schürrer 提交于
      When we build a query with an inline value that is a numeric (e.g.
      because it's out of range for an int4) PostgreSQL doesn't use an index
      on the column, since it's now comparing numerics and not int4s.
      
      This leads to a _very_ slow query.
      
      When we use bound parameters instead of inline values PostgreSQL
      raises numeric_value_out_of_range since no automatic coercion happens.
      f317cc8b
  6. 25 1月, 2014 1 次提交
  7. 22 1月, 2014 1 次提交
    • J
      Ensure AR #second, #third, etc. finders work through associations · 03855e79
      Jason Meller 提交于
      This commit fixes two regressions introduced in cafe31a0 where
      newly created finder methods #second, #third, #forth, and #fifth
      caused a NoMethodError error on reload associations and where we
      were pulling the wrong element out of cached associations.
      
      Examples:
      
        some_book.authors.reload.second
      
        # Before
        # => NoMethodError: undefined method 'first' for nil:NilClass
      
        # After
        # => #<Author id: 2, name: "Sally Second", ...>
      
        some_book.first.authors.first
        some_book.first.authors.second
      
        # Before
        # => #<Author id: 1, name: "Freddy First", ...>
        # => #<Author id: 1, name: "Freddy First", ...>
      
        # After
        # => #<Author id: 1, name: "Freddy First", ...>
        # => #<Author id: 2, name: "Sally Second", ...>
      
      Fixes #13783.
      03855e79
  8. 21 1月, 2014 1 次提交
    • J
      Ensure #second acts like #first AR finder · cafe31a0
      Jason Meller 提交于
      This commit bring the famous ordinal Array instance methods defined
      in ActiveSupport into ActiveRecord as fully-fledged finders.
      
      These finders ensure a default ascending order of the table's primary
      key, and utilize the OFFSET SQL verb to locate the user's desired
      record. If an offset is defined in the query, calling #second adds
      to the offset to get the actual desired record.
      
      Fixes #13743.
      cafe31a0
  9. 16 1月, 2014 1 次提交
  10. 13 12月, 2013 1 次提交
  11. 11 12月, 2013 1 次提交
    • L
      Prevent invalid code when using dynamic finders with Ruby's reserved words. · 23ce3e5f
      Lauro Caetano 提交于
      The dynamic finder was creating the method signature with the parameters name,
      which may have reserved words and this way creating invalid Ruby code.
      
      Closes: #13261
      
          Example:
      
              # Before
              Dog.find_by_alias('dog name')
      
              # Was creating this method
              def self.find_by_alias(alias, options = {})
      
              # After
              Dog.find_by_alias('dog name')
      
              # Will create this method
              def self.find_by_alias(_alias, options = {})
      23ce3e5f
  12. 06 12月, 2013 1 次提交
  13. 04 12月, 2013 1 次提交
  14. 03 12月, 2013 1 次提交
  15. 10 11月, 2013 1 次提交
  16. 09 11月, 2013 1 次提交
  17. 25 10月, 2013 1 次提交
  18. 21 10月, 2013 1 次提交
  19. 05 9月, 2013 1 次提交
  20. 19 8月, 2013 1 次提交
    • X
      let AR::FinderMethods#exists? return singletons in all cases [closes #11592] · 565c367d
      Xavier Noria 提交于
      This fixes a regression. The documentation said in its introduction
      paragraph that the method returns truthy/falsy, but then below it
      was said that if there were no arguments you'd get `true` or `false`.
      Also when the argument is exactly `false` a singleton is documented
      to be returned.
      
      The method was not returning the singletons so it didn't conform to
      those special cases.
      
      The best solution here seems to be to just return singletons in all
      cases. This solution is backwards compatible. Also, the contract
      has been revised because it has no sense that the predicate varies
      that way depending on the input. I bet the previous contract was just
      an accident, not something mixed on purpose.
      
      Conflicts:
      	activerecord/lib/active_record/relation/finder_methods.rb
      	activerecord/test/cases/finder_test.rb
      565c367d
  21. 29 7月, 2013 1 次提交
  22. 22 7月, 2013 1 次提交
    • B
      Don't allow `quote_value` to be called without a column · 31a43ebc
      Ben Woosley 提交于
      Some adapters require column information to do their job properly.
      By enforcing the provision of the column for this internal method
      we ensure that those using adapters that require column information
      will always get the proper behavior.
      31a43ebc
  23. 10 5月, 2013 1 次提交
    • B
      Fix that #exists? can produce invalid SQL: "SELECT DISTINCT DISTINCT" · 15d6e4dc
      Ben Woosley 提交于
      The combination of a :uniq => true association and the #distinct call
      in #construct_limited_ids_condition combine to create invalid SQL, because
      we're explicitly selecting DISTINCT, and also sending #distinct on to AREL,
      via the relation#distinct_value.
      
      Rather than build a select distinct clause in #construct_limited_ids_condition,
      I set #distinct! and pass just the columns into the select statement.
      This requires introducing a #columns_for_distinct method to return the
      select columns but not the statement itself.
      15d6e4dc
  24. 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
  25. 27 4月, 2013 1 次提交
  26. 24 4月, 2013 1 次提交
  27. 15 3月, 2013 1 次提交
    • Y
      rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works. · a1bb6c8b
      Yves Senn 提交于
      The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our
      Relation API is close to SQL terms I renamed `#uniq` to `#distinct`.
      
      There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue
      to work. I also updated the documentation to promote the use of `#distinct`.
      a1bb6c8b
  28. 09 2月, 2013 1 次提交
  29. 08 2月, 2013 1 次提交
  30. 03 1月, 2013 1 次提交
  31. 14 11月, 2012 1 次提交
  32. 13 11月, 2012 1 次提交
  33. 09 9月, 2012 1 次提交
    • E
      Raise MissingAttributeError on query methods · 4f107da4
      Ernie Miller 提交于
      When calling a query method on an attribute that was not selected by
      an ActiveRecord query, an ActiveModel::MissingAttributeError is not
      raised. Instead, a nil value is returned, which will return false once
      cast to boolean.
      
      This is undesirable, as we should not give the impression that we know
      the attribute's boolean value when we haven't loaded the attribute's
      (possibly) non-boolean value from the database.
      
      This issue is present on versions going back as far as 2.3, at least.
      4f107da4
  34. 03 8月, 2012 1 次提交
    • J
      Remove ActiveRecord::Base.to_a · 55b24888
      Jon Leighton 提交于
      On reflection, it seems like a bit of a weird method to have on
      ActiveRecord::Base, and it shouldn't be needed most of the time anyway.
      55b24888
  35. 28 7月, 2012 1 次提交