1. 13 5月, 2019 1 次提交
  2. 25 4月, 2019 2 次提交
  3. 19 4月, 2019 1 次提交
    • R
      Deprecate `where.not` working as NOR and will be changed to NAND in Rails 6.1 · 12a9664f
      Ryuta Kamizono 提交于
      `where.not` with polymorphic association is partly fixed incidentally at
      213796fb (refer #33493, #26207, #17010, #16983, #14161), and I've added
      test case e9ba12f7 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.
      12a9664f
  4. 17 4月, 2019 1 次提交
    • L
      Add collection cache versioning · 4f2ac80d
      Lachlan Sylvester 提交于
      Cache versioning enables the same cache key to be reused when the object
      being cached changes by moving the volatile part of the cache key out of
      the cache key and into a version that is embedded in the cache entry.
      
      This is already occurring when the object being cached is an
      `ActiveRecord::Base`, but when caching an `ActiveRecord::Relation`
      we are currently still putting the volatile information (max updated at
      and count) as part of the cache key.
      
      This PR moves the volatile part of the relations `cache_key` into the
      `cache_version` to support recycling cache keys for
      `ActiveRecord::Relation`s.
      4f2ac80d
  5. 16 4月, 2019 2 次提交
    • R
      Fix dirty tracking after rollback. · 63ff495b
      Ryuta Kamizono 提交于
      Currently the rollback only restores primary key value, `new_record?`,
      `destroyed?`, and `frozen?`. Since the `save` clears current dirty
      attribute states, retrying save after rollback will causes no change
      saved if partial writes is enabled (by default).
      
      This makes `remember_transaction_record_state` remembers original values
      then restores dirty attribute states after rollback.
      
      Fixes #15018.
      Fixes #30167.
      Fixes #33868.
      Fixes #33443.
      Closes #33444.
      Closes #34504.
      63ff495b
    • R
      Add CHANGELOG entry for d1107f4d · 20b94af9
      Ryuta Kamizono 提交于
      [ci skip]
      20b94af9
  6. 15 4月, 2019 1 次提交
    • Y
      make change_column_comment and change_table_comment invertible · 1fe71ebd
      Yoshiyuki Kinjo 提交于
      We can revert migrations using `change_column_comment` or
      `change_table_comment` at current master.
      However, results are not what we expect: comments are remained in new
      status.
      This change tells previous comment to these methods in a way like
      `change_column_default`.
      1fe71ebd
  7. 12 4月, 2019 1 次提交
    • R
      Don't call after_commit callbacks despite a record isn't saved · 9252da96
      Ryuta Kamizono 提交于
      Regardless of a record isn't saved (e.g. validation is failed),
      `after_commit` / `after_rollback` callbacks are invoked for now.
      
      To fix the issue, this adds a record to the current transaction only
      when a record is actually saved.
      
      Fixes #29747.
      Closes #29833.
      9252da96
  8. 07 4月, 2019 1 次提交
    • R
      Raise `ArgumentError` for invalid `:limit` and `:precision` like as other options · 20da6c7e
      Ryuta Kamizono 提交于
      When I've added new `:size` option in #35071, I've found that invalid
      `:limit` and `:precision` raises `ActiveRecordError` unlike other
      invalid options.
      
      I think that is hard to distinguish argument errors and statement
      invalid errors since the `StatementInvalid` is a subclass of the
      `ActiveRecordError`.
      
      https://github.com/rails/rails/blob/c9e4c848eeeb8999b778fa1ae52185ca5537fffe/activerecord/lib/active_record/errors.rb#L103
      
      ```ruby
      begin
        # execute any migration
      rescue ActiveRecord::StatementInvalid
        # statement invalid
      rescue ActiveRecord::ActiveRecordError, ArgumentError
        # `ActiveRecordError` except `StatementInvalid` is maybe an argument error
      end
      ```
      
      I'd say this is the inconsistency worth fixing.
      
      Before:
      
      ```ruby
      add_column :items, :attr1, :binary,   size: 10      # => ArgumentError
      add_column :items, :attr2, :decimal,  scale: 10     # => ArgumentError
      add_column :items, :attr3, :integer,  limit: 10     # => ActiveRecordError
      add_column :items, :attr4, :datetime, precision: 10 # => ActiveRecordError
      ```
      
      After:
      
      ```ruby
      add_column :items, :attr1, :binary,   size: 10      # => ArgumentError
      add_column :items, :attr2, :decimal,  scale: 10     # => ArgumentError
      add_column :items, :attr3, :integer,  limit: 10     # => ArgumentError
      add_column :items, :attr4, :datetime, precision: 10 # => ArgumentError
      ```
      20da6c7e
  9. 05 4月, 2019 1 次提交
    • R
      Association loading isn't to be affected by scoping consistently · 17f2f305
      Ryuta Kamizono 提交于
      Follow-up of 5c71000d, #29834, and #30271.
      
      Currently, preloading and eager loading are not to be affected by
      scoping, with the exception of `unscoped`.
      
      But non eager loaded association access is still affected by scoping.
      
      Although this is a breaking change, the association loading will work
      consistently whether preloaded / eager loaded or not.
      
      Before:
      
      ```ruby
      Post.where("1=0").scoping do
        Comment.find(1).post                   # => nil
        Comment.preload(:post).find(1).post    # => #<Post id: 1, ...>
        Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
      end
      ```
      
      After:
      
      ```ruby
      Post.where("1=0").scoping do
        Comment.find(1).post                   # => #<Post id: 1, ...>
        Comment.preload(:post).find(1).post    # => #<Post id: 1, ...>
        Comment.eager_load(:post).find(1).post # => #<Post id: 1, ...>
      end
      ```
      
      Fixes #34638.
      Fixes #35398.
      17f2f305
  10. 03 4月, 2019 5 次提交
  11. 02 4月, 2019 1 次提交
  12. 31 3月, 2019 1 次提交
  13. 30 3月, 2019 2 次提交
    • R
      Fix callbacks on has_many :through associations (#33249) · 2e3bba3e
      Ryan Kerr 提交于
      When adding a child record via a has_many :through association,
      build_through_record would previously build the join record, and then
      assign the child record and source_type option to it.  Because the
      before_add and after_add callbacks are called as part of build, however,
      this caused the callbacks to receive incomplete records, specifically
      without the other end of the has_many :through association.  Collecting
      all attributes before building the join record ensures the callbacks
      receive the fully constructed record.
      2e3bba3e
    • D
      Add `ActiveRecord::Relation#extract_associated` for extracting associated record (#35784) · 4e076b03
      David Heinemeier Hansson 提交于
      * Add `ActiveRecord::Relation#extract_associated` for extracting associated records from a relation
      4e076b03
  14. 25 3月, 2019 1 次提交
  15. 22 3月, 2019 1 次提交
    • M
      Add Relation#annotate for SQL commenting · f4182580
      Matt Yoho 提交于
      This patch has two main portions:
      
      1. Add SQL comment support to Arel via Arel::Nodes::Comment.
      2. Implement a Relation#annotate method on top of that.
      
      == Adding SQL comment support
      
      Adds a new Arel::Nodes::Comment node that represents an optional SQL
      comment and teachers the relevant visitors how to handle it.
      
      Comment nodes may be added to the basic CRUD statement nodes and set
      through any of the four (Select|Insert|Update|Delete)Manager objects.
      
      For example:
      
          manager = Arel::UpdateManager.new
          manager.table table
          manager.comment("annotation")
          manager.to_sql # UPDATE "users" /* annotation */
      
      This new node type will be used by ActiveRecord::Relation to enable
      query annotation via SQL comments.
      
      == Implementing the Relation#annotate method
      
      Implements `ActiveRecord::Relation#annotate`, which accepts a comment
      string that will be appeneded to any queries generated by the relation.
      
      Some examples:
      
          relation = Post.where(id: 123).annotate("metadata string")
          relation.first
          # SELECT "posts".* FROM "posts" WHERE "posts"."id" = 123
          # LIMIT 1 /* metadata string */
      
          class Tag < ActiveRecord::Base
            scope :foo_annotated, -> { annotate("foo") }
          end
          Tag.foo_annotated.annotate("bar").first
          # SELECT "tags".* FROM "tags" LIMIT 1 /* foo */ /* bar */
      
      Also wires up the plumbing so this works with `#update_all` and
      `#delete_all` as well.
      
      This feature is useful for instrumentation and general analysis of
      queries generated at runtime.
      f4182580
  16. 16 3月, 2019 1 次提交
    • R
      Support Optimizer Hints · 97347d8c
      Ryuta Kamizono 提交于
      We as Arm Treasure Data are using Optimizer Hints with a monkey patch
      (https://gist.github.com/kamipo/4c8539f0ce4acf85075cf5a6b0d9712e),
      especially in order to use `MAX_EXECUTION_TIME` (refer #31129).
      
      Example:
      
      ```ruby
      class Job < ApplicationRecord
        default_scope { optimizer_hints("MAX_EXECUTION_TIME(50000) NO_INDEX_MERGE(jobs)") }
      end
      ```
      
      Optimizer Hints is supported not only for MySQL but also for most
      databases (PostgreSQL on RDS, Oracle, SQL Server, etc), it is really
      helpful to turn heavy queries for large scale applications.
      97347d8c
  17. 11 3月, 2019 1 次提交
    • E
      Prep release · 7c87fd56
      eileencodes 提交于
      * Update RAILS_VERSION
      * Bundle
      * rake update_versions
      * rake changelog:header
      7c87fd56
  18. 10 3月, 2019 1 次提交
  19. 08 3月, 2019 1 次提交
  20. 06 3月, 2019 1 次提交
    • B
      Add insert_all to ActiveRecord models (#35077) · 91ed21b3
      Bob Lail 提交于
      Adds a method to ActiveRecord allowing records to be inserted in bulk without instantiating ActiveRecord models. This method supports options for handling uniqueness violations by skipping duplicate records or overwriting them in an UPSERT operation.
      
      ActiveRecord already supports bulk-update and bulk-destroy actions that execute SQL UPDATE and DELETE commands directly. It also supports bulk-read actions through `pluck`. It makes sense for it also to support bulk-creation.
      91ed21b3
  21. 05 3月, 2019 1 次提交
  22. 04 3月, 2019 3 次提交
  23. 27 2月, 2019 1 次提交
  24. 26 2月, 2019 2 次提交
  25. 25 2月, 2019 2 次提交
  26. 20 2月, 2019 1 次提交
    • R
      Don't allow `where` with non numeric string matches to 0 values · 357cd23d
      Ryuta Kamizono 提交于
      This is a follow-up of #35310.
      
      Currently `Topic.find_by(id: "not-a-number")` matches to a `id = 0`
      record. That is considered as silently leaking information.
      
      If non numeric string is given to find by an integer column, it should
      not be matched to any record.
      
      Related #12793.
      357cd23d
  27. 19 2月, 2019 1 次提交
  28. 18 2月, 2019 1 次提交
  29. 16 2月, 2019 1 次提交