1. 04 9月, 2013 1 次提交
  2. 31 8月, 2013 1 次提交
  3. 24 7月, 2013 1 次提交
  4. 16 7月, 2013 2 次提交
  5. 15 7月, 2013 1 次提交
  6. 22 6月, 2013 1 次提交
  7. 18 5月, 2013 1 次提交
  8. 08 5月, 2013 1 次提交
  9. 20 4月, 2013 2 次提交
    • X
      if singletons belong to the contract, test them · 0400a7ff
      Xavier Noria 提交于
      Object#respond_to? returns singletons and thus we inherit that contract.
      The implementation of the predicate is good, but the test is only
      checking boolean semantics, which in this case is not enough.
      0400a7ff
    • N
      fix respond_to? for non selected column · 66001f36
      Neeraj Singh 提交于
      fixes #4208
      
      If a query selects only a few columns and gives custom names to
      those columns then respond_to? was returning true for the non
      selected columns. However calling those non selected columns
      raises exception.
      
          post = Post.select("'title' as post_title").first
      
      In the above case when `post.body` is invoked then an exception is
      raised since `body` attribute is not selected. Howevere `respond_to?`
      did not behave correctly.
      
          pos.respond_to?(:body) #=> true
      
      Reason was that Active Record calls `super` to pass the call to
      Active Model and all the columns are defined on Active Model.
      
      Fix is to actually check if the data returned from the db contains
      the data for column in question.
      66001f36
  10. 11 4月, 2013 2 次提交
    • Y
      Address ORA-00979: not a GROUP BY expression error · 0997a14b
      Yasuo Honda 提交于
      0997a14b
    • J
      While merging relations preserve context for joins · dc764fcc
      Jared Armstrong and Neeraj Singh 提交于
      Fixes #3002. Also see #5494.
      
      ```
      class Comment < ActiveRecord::Base
        belongs_to :post
      end
      
      class Author < ActiveRecord::Base
        has_many :posts
      end
      
      class Post < ActiveRecord::Base
        belongs_to :author
        has_many :comments
      end
      ```
      
      `Comment.joins(:post).merge(Post.joins(:author).merge(Author.where(:name => "Joe Blogs"))).all` would
      fail with `ActiveRecord::ConfigurationError: Association named 'author' was not found on Comment`.
      
      It is failing because `all` is being called on relation which looks like this after all the merging:
      `{:joins=>[:post, :author], :where=>[#<Arel::Nodes::Equality: ....}`. In this relation all the context that
      `Post` was joined with `Author` is lost and hence the error that `author` was not found on `Comment`.
      
      Ths solution is to build JoinAssociation when two relations with join information are being merged. And later
      while building the arel use the  previously built `JoinAssociation` record in `JoinDependency#graft` to
      build the right from clause.
      
      Thanks to Jared Armstrong (https://github.com/armstrjare) for most of the work. I ported it to make it
      compatible with new code base.
      dc764fcc
  11. 15 3月, 2013 1 次提交
    • Y
      rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works. · a1bb6c8b
      Yves Senn 提交于
      The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our
      Relation API is close to SQL terms I renamed `#uniq` to `#distinct`.
      
      There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue
      to work. I also updated the documentation to promote the use of `#distinct`.
      a1bb6c8b
  12. 26 2月, 2013 1 次提交
  13. 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
  14. 29 10月, 2012 1 次提交
  15. 03 8月, 2012 1 次提交
    • J
      Allow Relation#merge to take a proc. · bf2df6e7
      Jon Leighton 提交于
      This was requested by DHH to allow creating of one's own custom
      association macros.
      
      For example:
      
          module Commentable
            def has_many_comments(extra)
              has_many :comments, -> { where(:foo).merge(extra) }
            end
          end
      
          class Post < ActiveRecord::Base
            extend Commentable
            has_many_comments -> { where(:bar) }
          end
      bf2df6e7
  16. 14 7月, 2012 1 次提交
  17. 03 6月, 2012 1 次提交
  18. 17 5月, 2012 1 次提交
  19. 25 4月, 2012 2 次提交
  20. 14 4月, 2012 1 次提交
  21. 13 4月, 2012 10 次提交
  22. 17 1月, 2012 4 次提交
  23. 04 1月, 2012 1 次提交
  24. 29 12月, 2011 1 次提交