1. 14 5月, 2020 2 次提交
  2. 09 5月, 2020 2 次提交
  3. 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
  4. 15 2月, 2019 1 次提交
  5. 14 2月, 2019 1 次提交
  6. 05 2月, 2019 1 次提交
    • R
      Chaining named scope is no longer leaking to class level querying methods · 2935d075
      Ryuta Kamizono 提交于
      Active Record uses `scoping` to delegate to named scopes from relations
      for propagating the chaining source scope. It was needed to restore the
      source scope in named scopes, but it was caused undesired behavior that
      pollute all class level querying methods.
      
      Example:
      
      ```ruby
      class Topic < ActiveRecord::Base
        scope :toplevel, -> { where(parent_id: nil) }
        scope :children, -> { where.not(parent_id: nil) }
        scope :has_children, -> { where(id: Topic.children.select(:parent_id)) }
      end
      
      # Works as expected.
      Topic.toplevel.where(id: Topic.children.select(:parent_id))
      
      # Doesn't work due to leaking `toplevel` to `Topic.children`.
      Topic.toplevel.has_children
      ```
      
      Since #29301, the receiver in named scopes has changed from the model
      class to the chaining source scope, so the polluting class level
      querying methods is no longer required for that purpose.
      
      Fixes #14003.
      2935d075
  7. 18 1月, 2019 1 次提交
  8. 26 9月, 2018 1 次提交
  9. 26 4月, 2018 1 次提交
  10. 19 4月, 2018 1 次提交
  11. 30 3月, 2018 1 次提交
  12. 26 1月, 2018 3 次提交
  13. 28 11月, 2017 1 次提交
  14. 09 11月, 2017 2 次提交
  15. 13 8月, 2017 1 次提交
  16. 20 7月, 2017 1 次提交
  17. 02 7月, 2017 1 次提交
  18. 01 7月, 2017 1 次提交
  19. 01 6月, 2017 1 次提交
  20. 19 3月, 2017 1 次提交
    • R
      Use `load` rather than `collect` for force loading · 59db5f22
      Ryuta Kamizono 提交于
      Since b644964b `ActiveRecord::Relation` includes `Enumerable` so
      delegating `collect`, `all?`, and `include?` are also unneeded.
      `collect` without block returns `Enumerable` without preloading by that.
      We should use `load` rather than `collect` for force loading.
      59db5f22
  21. 25 2月, 2017 1 次提交
  22. 29 10月, 2016 1 次提交
  23. 17 9月, 2016 1 次提交
  24. 16 8月, 2016 1 次提交
  25. 07 8月, 2016 3 次提交
  26. 19 7月, 2016 1 次提交
    • S
      Fix the calling `merge` method at first in a scope · cf2574b1
      suginoy 提交于
      Changing the order of method chaining `merge` and other query
      method such as `joins` should produce the same result.
      
      ```ruby
      class Topic < ApplicationRecord
        scope :safe_chaininig,   -> { joins(:comments).merge(Comment.newest) }
        scope :unsafe_chaininig, -> { merge(Comment.newest).joins(:comments) } #=> NoMethodError
      end
      ```
      cf2574b1
  27. 05 5月, 2016 1 次提交
  28. 03 5月, 2016 1 次提交
    • S
      Do not delegate `AR::Base#empty?` to `all` · 98264a13
      Sean Griffin 提交于
      Unlike `one?` and `none?`, `empty?` has interactions with methods
      outside of enumerable. It also doesn't fit in the same vein.
      `Topic.any?` makes sense. `Topic.empty?` does not, as `Topic` is not a
      container.
      
      Fixes #24808
      Close #24812
      98264a13
  29. 29 3月, 2016 1 次提交
  30. 28 1月, 2016 3 次提交
  31. 26 8月, 2015 1 次提交