1. 30 7月, 2013 1 次提交
    • R
      Revert change on ActiveRecord::Relation#order method that prepends new · 92c5a224
      Rafael Mendonça França 提交于
      order on the old ones
      
      The previous behavior added a major backward incompatibility since it
      impossible to have a upgrade path without major changes on the
      application code.
      
      We are taking the most conservative path to be consistent with the idea
      of having a smoother upgrade on Rails 4.
      
      We are reverting the behavior for what was in Rails 3.x and,
      if needed, we will implement a new API to prepend the order clauses in
      Rails 4.1.
      92c5a224
  2. 16 7月, 2013 1 次提交
  3. 05 7月, 2013 2 次提交
  4. 03 7月, 2013 1 次提交
  5. 29 6月, 2013 1 次提交
  6. 28 6月, 2013 1 次提交
  7. 22 5月, 2013 2 次提交
  8. 11 5月, 2013 1 次提交
  9. 23 4月, 2013 1 次提交
  10. 16 3月, 2013 1 次提交
  11. 15 3月, 2013 3 次提交
  12. 08 3月, 2013 1 次提交
  13. 20 2月, 2013 1 次提交
  14. 09 2月, 2013 1 次提交
  15. 08 2月, 2013 1 次提交
  16. 28 1月, 2013 1 次提交
    • J
      Prevent Relation#merge from collapsing wheres on the RHS · c8d88990
      Jon Leighton 提交于
      This caused a bug with the new associations implementation, because now
      association conditions are represented as Arel nodes internally right up
      to when the whole thing gets turned to SQL.
      
      In Rails 3.2, association conditions get turned to raw SQL early on,
      which prevents Relation#merge from interfering.
      
      The current implementation was buggy when a default_scope existed on the
      target model, since we would basically end up doing:
      
        default_scope.merge(association_scope)
      
      If default_scope contained a where(foo: 'a') and association_scope
      contained a where(foo: 'b').where(foo: 'c') then the merger would see
      that the same column is representated on both sides of the merge and
      collapse the wheres to all but the last: where(foo: 'c')
      
      Now, the RHS of the merge is left alone.
      
      Fixes #8990
      c8d88990
  17. 20 1月, 2013 1 次提交
  18. 06 1月, 2013 1 次提交
  19. 05 1月, 2013 2 次提交
  20. 30 11月, 2012 1 次提交
    • J
      Use separate Relation subclasses for each AR class · 64c53d7c
      Jon Leighton 提交于
      At present, ActiveRecord::Delegation compiles delegation methods on a
      global basis. The compiled methods apply to all subsequent Relation
      instances. This creates several problems:
      
      1) After Post.all.recent has been called, User.all.respond_to?(:recent)
         will be true, even if User.all.recent will actually raise an error due
         to no User.recent method existing. (See #8080.)
      
      2) Depending on the AR class, the delegation should do different things.
         For example, if a Post.zip method exists, then Post.all.zip should call
         it. But this will then result in User.zip being called by a subsequent
         User.all.zip, even if User.zip does not exist, when in fact
         User.all.zip should call User.all.to_a.zip. (There are various
         variants of this problem.)
      
      We are creating these compiled delegations in order to avoid method
      missing and to avoid repeating logic on each invocation.
      
      One way of handling these issues is to add additional checks in various
      places to ensure we're doing the "right thing". However, this makes the
      compiled methods signficantly slower. In which case, there's almost no
      point in avoiding method_missing at all. (See #8127 for a proposed
      solution which takes this approach.)
      
      This is an alternative approach which involves creating a subclass of
      ActiveRecord::Relation for each AR class represented. So, with this
      patch, Post.all.class != User.all.class. This means that the delegations
      are compiled for and only apply to a single AR class. A compiled method
      for Post.all will not be invoked from User.all.
      
      This solves the above issues without incurring significant performance
      penalties. It's designed to be relatively seamless, however the downside
      is a bit of complexity and potentially confusion for a user who thinks
      that Post.all and User.all should be instances of the same class.
      
      Benchmark
      ---------
      
      require 'active_record'
      require 'benchmark/ips'
      
      class Post < ActiveRecord::Base
        establish_connection adapter: 'sqlite3', database: ':memory:'
        connection.create_table :posts
      
        def self.omg
          :omg
        end
      end
      
      relation = Post.all
      
      Benchmark.ips do |r|
        r.report('delegation')   { relation.omg }
        r.report('constructing') { Post.all }
      end
      
      Before
      ------
      
      Calculating -------------------------------------
                delegation      4392 i/100ms
              constructing      4780 i/100ms
      -------------------------------------------------
                delegation   144235.9 (±27.7%) i/s -     663192 in   5.038075s
              constructing   182015.5 (±21.2%) i/s -     850840 in   5.005364s
      
      After
      -----
      
      Calculating -------------------------------------
                delegation      6677 i/100ms
              constructing      6260 i/100ms
      -------------------------------------------------
                delegation   166828.2 (±34.2%) i/s -     754501 in   5.001430s
              constructing   116575.5 (±18.6%) i/s -     563400 in   5.036690s
      
      Comments
      --------
      
      Bear in mind that the standard deviations in the above are huge, so we
      can't compare the numbers too directly. However, we can conclude that
      Relation construction has become a little slower (as we'd expect), but
      not by a huge huge amount, and we can still construct a large number of
      Relations quite quickly.
      64c53d7c
  21. 19 11月, 2012 1 次提交
  22. 18 11月, 2012 1 次提交
  23. 29 10月, 2012 1 次提交
  24. 19 10月, 2012 2 次提交
  25. 12 10月, 2012 1 次提交
  26. 10 10月, 2012 1 次提交
  27. 24 8月, 2012 1 次提交
  28. 19 8月, 2012 1 次提交
  29. 17 8月, 2012 1 次提交
    • E
      Fix merge error when Equality LHS is non-attribute · b127d86c
      Ernie Miller 提交于
      This is at best a band-aid for a more proper fix, since it won't truly
      handle the removal of the previous equality condition of these other
      nodes. I'm planning to put in some work on ARel toward supporting that
      goal.
      
      Related: rails/arel#130, ernie/squeel#153, ernie/squeel#156
      b127d86c
  30. 15 8月, 2012 1 次提交
  31. 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
  32. 02 8月, 2012 1 次提交
    • J
      Add `Relation#load` · 437851ea
      Jon Leighton 提交于
      This method explicitly loads the records and then returns `self`.
      
      Rather than deciding between "do I want an array or a relation?",
      most people are actually asking themselves "do I want to eager load
      or lazy load?" Therefore, this method provides a way to explicitly
      eager-load without having to switch from a `Relation` to an array.
      
      Example:
      
          @posts = Post.where(published: true).load
      437851ea
  33. 31 7月, 2012 1 次提交
  34. 28 7月, 2012 1 次提交