1. 06 11月, 2018 1 次提交
    • E
      Fix inspect with non-primary key id attribute · 65cd0fda
      Eugene Kenny 提交于
      The `read_attribute` method always returns the primary key when asked to
      read the `id` attribute, even if the primary key isn't named `id`, and
      even if another attribute named `id` exists.
      
      For the `inspect`, `attribute_for_inspect` and `pretty_print` methods,
      this behaviour is undesirable, as they're used to examine the internal
      state of the record. By using `_read_attribute` instead, we'll get the
      real value of the `id` attribute.
      65cd0fda
  2. 26 9月, 2018 1 次提交
  3. 07 6月, 2018 1 次提交
  4. 28 5月, 2018 1 次提交
  5. 27 5月, 2018 1 次提交
    • R
      Fix that association's after_touch is not called with counter cache · 17bf6203
      Ryuta Kamizono 提交于
      Since #31405, using `#increment!` with touch option instead of `#touch`
      to touch belongs_to association if counter cache is enabled. It caused
      the regression since `#increment!` won't invoke after_touch callbacks
      even if touch option is given.
      To fix the regression, make `#increment!` invokes after_touch callbacks
      if touch option is given.
      
      Fixes #31559.
      Fixes #32408.
      17bf6203
  6. 11 5月, 2018 1 次提交
    • R
      `becomes` should clear the mutation tracker which is created in `after_initialize` · ab3ad6a9
      Ryuta Kamizono 提交于
      `becomes` creates new object and copies attributes from the receiver. If
      new object has mutation tracker which is created in `after_initialize`,
      it should be cleared since it is for discarded attributes.
      
      But if the receiver doesn't have mutation tracker yet, it will not be
      cleared properly.
      
      It should be cleared regardless of whether the receiver has mutation
      tracker or not.
      
      Fixes #32867.
      ab3ad6a9
  7. 30 3月, 2018 1 次提交
  8. 27 3月, 2018 1 次提交
    • R
      Bring back private class methods accessibility in named scope · b9be64cc
      Ryuta Kamizono 提交于
      The receiver in a scope was changed from `klass` to `relation` itself
      for all scopes (named scope, default_scope, and association scope)
      behaves consistently.
      
      In addition. Before 5.2, if both an AR model class and a Relation
      instance have same named methods (e.g. `arel_attribute`,
      `predicate_builder`, etc), named scope doesn't respect relation instance
      information.
      
      For example:
      
      ```ruby
      class Post < ActiveRecord::Base
        has_many :comments1, class_name: "RecentComment1"
        has_many :comments2, class_name: "RecentComment2"
      end
      
      class RecentComment1 < ActiveRecord::Base
        self.table_name = "comments"
        default_scope { where(arel_attribute(:created_at).gteq(2.weeks.ago)) }
      end
      
      class RecentComment2 < ActiveRecord::Base
        self.table_name = "comments"
        default_scope { recent_updated }
        scope :recent_updated, -> { where(arel_attribute(:updated_at).gteq(2.weeks.ago)) }
      end
      ```
      
      If eager loading `Post.eager_load(:comments1, :comments2).to_a`,
      `:comments1` (default_scope) respects aliased table name, but
      `:comments2` (using named scope) may not work correctly since named
      scope doesn't respect relation instance information. See also 801ccab2.
      
      But this is a breaking change between releases without deprecation.
      I decided to bring back private class methods accessibility in named
      scope.
      
      Fixes #31740.
      Fixes #32331.
      b9be64cc
  9. 22 12月, 2017 1 次提交
  10. 20 7月, 2017 1 次提交
  11. 02 7月, 2017 1 次提交
  12. 01 7月, 2017 1 次提交
  13. 24 5月, 2017 1 次提交
  14. 23 12月, 2016 1 次提交
  15. 08 8月, 2016 1 次提交
    • X
      code gardening: removes redundant selfs · a9dc4545
      Xavier Noria 提交于
      A few have been left for aesthetic reasons, but have made a pass
      and removed most of them.
      
      Note that if the method `foo` returns an array, `foo << 1`
      is a regular push, nothing to do with assignments, so
      no self required.
      a9dc4545
  16. 07 8月, 2016 2 次提交
  17. 20 7月, 2016 1 次提交
  18. 06 9月, 2015 1 次提交
  19. 22 7月, 2015 1 次提交
  20. 26 11月, 2013 1 次提交
  21. 11 9月, 2013 1 次提交
  22. 18 8月, 2013 1 次提交
  23. 25 7月, 2013 1 次提交
  24. 24 1月, 2013 3 次提交
  25. 13 11月, 2012 1 次提交
  26. 05 11月, 2012 1 次提交
  27. 28 7月, 2012 1 次提交
  28. 22 6月, 2012 1 次提交
  29. 27 4月, 2012 1 次提交
  30. 26 4月, 2012 1 次提交
  31. 25 4月, 2012 1 次提交
  32. 22 3月, 2012 1 次提交
    • J
      Deprecate eager-evaluated scopes. · 0a12a5f8
      Jon Leighton 提交于
      Don't use this:
      
          scope :red, where(color: 'red')
          default_scope where(color: 'red')
      
      Use this:
      
          scope :red, -> { where(color: 'red') }
          default_scope { where(color: 'red') }
      
      The former has numerous issues. It is a common newbie gotcha to do
      the following:
      
          scope :recent, where(published_at: Time.now - 2.weeks)
      
      Or a more subtle variant:
      
          scope :recent, -> { where(published_at: Time.now - 2.weeks) }
          scope :recent_red, recent.where(color: 'red')
      
      Eager scopes are also very complex to implement within Active
      Record, and there are still bugs. For example, the following does
      not do what you expect:
      
          scope :remove_conditions, except(:where)
          where(...).remove_conditions # => still has conditions
      0a12a5f8
  33. 07 1月, 2012 1 次提交
  34. 24 12月, 2011 1 次提交
  35. 17 12月, 2011 1 次提交
  36. 13 9月, 2011 1 次提交
  37. 18 4月, 2011 1 次提交