1. 21 9月, 2020 1 次提交
  2. 17 8月, 2020 1 次提交
    • R
      Fix eager loading that non-select columns will be loaded · 46393182
      Ryuta Kamizono 提交于
      Related to #35210.
      
      We sometimes use `select` to limit unused columns for performance.
      
      For example, `GET /posts/1` (post detail) usually use (almost) all
      columns, but `GET /posts` (post list) does not always use all columns
      (e.g. use `id` and `title` for the list view, but `body` is not used).
      
      If an association is eager loaded, the limited `select` doesn't works as
      expected, eager loading will load all columns on the model, plus also
      load the `select` columns additionally. It works differently with
      natural load and preload. It means that changing natural load or preload
      to eager load (or vice versa) is unsafe.
      
      This fixes eager loading that always load all columns (plus extra
      `select` columns), to respect the `select` columns like as others.
      
      ```ruby
      post = Post.select("UPPER(title) AS title").first
      post.title # => "WELCOME TO THE WEBLOG"
      post.body  # => ActiveModel::MissingAttributeError
      
      # Rails 6.0 (ignore the `select` values)
      post = Post.select("UPPER(title) AS title").eager_load(:comments).first
      post.title # => "Welcome to the weblog"
      post.body  # => "Such a lovely day"
      
      # Rails 6.1 (respect the `select` values)
      post = Post.select("UPPER(title) AS title").eager_load(:comments).first
      post.title # => "WELCOME TO THE WEBLOG"
      post.body  # => ActiveModel::MissingAttributeError
      ```
      46393182
  3. 01 6月, 2020 1 次提交
    • R
      Use statement cache for `find_by` with aliased attribute · df94fdc2
      Ryuta Kamizono 提交于
      ```ruby
      class Post < ActiveRecord::Base
        alias_attribute :alias_id, :id
      end
      
      Benchmark.ips do |x|
        x.report("find_by alias") do
          Post.find_by(alias_id: 1)
        end
      end
      ```
      
      Before:
      
      ```
      Warming up --------------------------------------
             find_by alias   419.000  i/100ms
      Calculating -------------------------------------
             find_by alias      4.260k (± 3.9%) i/s -     21.369k in   5.023768s
      ```
      
      After:
      
      ```
      Warming up --------------------------------------
             find_by alias     1.182k i/100ms
      Calculating -------------------------------------
             find_by alias     12.122k (± 4.1%) i/s -     61.464k in   5.080451s
      ```
      df94fdc2
  4. 29 5月, 2020 1 次提交
  5. 27 5月, 2020 1 次提交
  6. 04 5月, 2020 1 次提交
  7. 27 1月, 2020 1 次提交
  8. 03 11月, 2019 1 次提交
  9. 11 10月, 2019 2 次提交
  10. 10 10月, 2019 1 次提交
  11. 10 7月, 2019 1 次提交
  12. 08 7月, 2019 1 次提交
  13. 19 6月, 2019 1 次提交
  14. 11 3月, 2019 1 次提交
  15. 24 2月, 2019 1 次提交
  16. 08 2月, 2019 1 次提交
    • R
      Fix `relation.exists?` with giving both `distinct` and `offset` · 07dcd99a
      Ryuta Kamizono 提交于
      The `distinct` affects (reduces) rows of the result, so it is important
      part when both `distinct` and `offset` are given.
      
      Replacing SELECT clause to `1 AS one` and removing `distinct` and
      `order` is just optimization for the `exists?`, we should not apply the
      optimization for that case.
      
      Fixes #35191.
      07dcd99a
  17. 19 1月, 2019 1 次提交
  18. 18 1月, 2019 3 次提交
    • R
      All of queries should return correct result even if including large number · 31ffbf8d
      Ryuta Kamizono 提交于
      Currently several queries cannot return correct result due to incorrect
      `RangeError` handling.
      
      First example:
      
      ```ruby
      assert_equal true, Topic.where(id: [1, 9223372036854775808]).exists?
      assert_equal true, Topic.where.not(id: 9223372036854775808).exists?
      ```
      
      The first example is obviously to be true, but currently it returns
      false.
      
      Second example:
      
      ```ruby
      assert_equal topics(:first), Topic.where(id: 1..9223372036854775808).find(1)
      ```
      
      The second example also should return the object, but currently it
      raises `RecordNotFound`.
      
      It can be seen from the examples, the queries including large number
      assuming empty result is not always correct.
      
      Therefore, This change handles `RangeError` to generate executable SQL
      instead of raising `RangeError` to users to always return correct
      result. By this change, it is no longer raised `RangeError` to users.
      31ffbf8d
    • B
      Ensure that AR::Relation#exists? allows only permitted params · 6410c70f
      bogdanvlviv 提交于
      Clarify changelog entry
      Related to #34891
      6410c70f
    • D
  19. 08 1月, 2019 1 次提交
  20. 21 12月, 2018 1 次提交
  21. 27 11月, 2018 1 次提交
    • T
      Make implicit order column configurable · 3b9982a3
      Tekin Suleyman 提交于
      When calling ordered finder methods such as +first+ or +last+ without an
      explicit order clause, ActiveRecord sorts records by primary key. This
      can result in unpredictable and surprising behaviour when the primary
      key is not an auto-incrementing integer, for example when it's a UUID.
      This change makes it possible to override the column used for implicit
      ordering such that +first+ and +last+ will return more predictable
      results. For Example:
      
        class Project < ActiveRecord::Base
          self.implicit_order_column = "created_at"
        end
      3b9982a3
  22. 27 10月, 2018 2 次提交
  23. 20 9月, 2018 1 次提交
  24. 01 8月, 2018 2 次提交
  25. 20 7月, 2018 1 次提交
  26. 22 6月, 2018 1 次提交
  27. 06 5月, 2018 1 次提交
  28. 19 4月, 2018 1 次提交
  29. 27 2月, 2018 1 次提交
  30. 23 2月, 2018 1 次提交
  31. 29 1月, 2018 2 次提交
  32. 26 1月, 2018 2 次提交
  33. 11 1月, 2018 1 次提交