1. 20 6月, 2015 1 次提交
    • S
      Use `Enumerable#sum` on `ActiveRecord::Relation` when a block is given · 7d14bd3f
      Sean Griffin 提交于
      This matches our behavior in other cases where useful enumerable methods
      might have a different definition in `Relation`. Wanting to actually
      enumerate over the records in this case is completely reasonable, and
      wanting `.sum` is reasonable for the same reason it is on `Enumerable`
      in the first place.
      7d14bd3f
  2. 31 5月, 2015 1 次提交
    • S
      Ensure symbols passed to `select` are always quoted · 0ef7e73f
      Sean Griffin 提交于
      Our general contract in Active Record is that strings are assumed to be
      SQL literals, and symbols are assumed to reference a column. If a from
      clause is given, we shouldn't include the table name, but we should
      still quote the value as if it were a column.
      
      Upon fixing this, the tests were still failing on SQLite. This was
      because the column name being returned by the query was `"\"join\""`
      instead of `"join"`. This is actually a bug in SQLite that was fixed a
      long time ago, but I was using the version of SQLite included by OS X
      which has this bug. Since I'm guessing this will be a common case for
      contributors, I also added an explicit check with a more helpful error
      message.
      
      Fixes #20360
      0ef7e73f
  3. 29 5月, 2015 2 次提交
  4. 28 5月, 2015 2 次提交
    • W
      Properly append preload / includes args on Merger · a01d164b
      Washington Luiz 提交于
      Couldn't find other way to get the association name from a given class
      other than looping through `reflect_on_all_associations` reflections ..
      
      Noticed this one while looking at this example:
      
      ```ruby
      class Product < ActiveRecord::Base
        has_many :variants
        has_many :translations
      end
      
      class Translation < ActiveRecord::Base
        belongs_to :product
      end
      
      class Variant < ActiveRecord::Base
        belongs_to :product
      end
      
      class BugTest < Minitest::Test
        def test_merge_stuff
          product = Product.create! name: 'huhu'
          variant = Variant.create! product_id: product.id
          Translation.create! locale: 'en', product_id: product.id
      
          product_relation = Product.all
                                    .preload(:translations)
                                    .joins(:translations)
                                    .merge(Translation.where(locale: 'en'))
                                    .where(name: 'huhu')
      
          assert_equal variant, Variant.joins(:product).merge(product_relation).first
        end
      end
      ```
      a01d164b
    • J
      Allow Relation#compact using delegation · 57daaef8
      Jordan Raine 提交于
      57daaef8
  5. 26 5月, 2015 1 次提交
    • Y
      deprecate `Relation#uniq` use `Relation#distinct` instead. · adfab2dc
      Yves Senn 提交于
      See #9683 for the reasons we switched to `distinct`.
      
      Here is the discussion that triggered the actual deprecation #20198.
      
      `uniq`, `uniq!` and `uniq_value` are still around.
      They will be removed in the next minor release after Rails 5.
      adfab2dc
  6. 15 5月, 2015 1 次提交
  7. 12 5月, 2015 1 次提交
  8. 11 5月, 2015 1 次提交
  9. 15 4月, 2015 1 次提交
  10. 14 4月, 2015 1 次提交
    • Y
      Add support for Set to Relation#where · 50cae600
      Yuki Nishijima 提交于
      Previously `#where` used to treat `Set`objects as nil, but now it treats
      them as an array:
      
        set = Set.new([1, 2])
        Author.where(:id => set)
        # => SELECT "authors".* FROM "authors" WHERE "authors"."id" IN (1, 2)
      50cae600
  11. 13 4月, 2015 1 次提交
  12. 11 4月, 2015 1 次提交
    • K
      Raise ArgumentError when find_by receives no arguments · 28375dd6
      Kohei Suzuki 提交于
      It fixes the strange error saying undefined method `take'.
      
      ```
      RelationTest#test_find_by_without_arg_behaves_same_with_find_by({}):
      NoMethodError: undefined method `take' for #<ActiveRecord::QueryMethods::WhereChain:0x007f9c55db1d68>
      ```
      28375dd6
  13. 31 3月, 2015 1 次提交
  14. 27 3月, 2015 2 次提交
  15. 26 3月, 2015 1 次提交
    • J
      Add `config.active_record.warn_on_records_fetched_greater_than` option · 4d6fbe29
      Jason Nochlin 提交于
      When set to an integer, a warning will be logged whenever a result set
      larger than the specified size is returned by a query. Fixes #16463
      
      The warning is outputed a module which is prepended in an initializer,
      so there will be no performance impact if
      `config.active_record.warn_on_records_fetched_greater_than` is not set.
      4d6fbe29
  16. 22 3月, 2015 1 次提交
    • P
      Fix referencing wrong aliases while joining tables of has many through · ba057a5e
      pinglamb 提交于
      association
      
      While joining table of has_many :through association, ActiveRecord will
      use the actual table name instead of through-join alias. It results with
      a wrong SQL and exception is raised. This only happens when calculation
      methods like #count is called.
      
      This issue is affecting Rails 4.1.x and 4.2.x as well.
      ba057a5e
  17. 17 3月, 2015 1 次提交
  18. 28 2月, 2015 2 次提交
  19. 25 2月, 2015 2 次提交
  20. 18 2月, 2015 2 次提交
  21. 17 2月, 2015 1 次提交
  22. 09 2月, 2015 1 次提交
  23. 07 2月, 2015 2 次提交
  24. 04 2月, 2015 1 次提交
    • S
      Respect custom primary keys for associations in `Relation#where` · cd0ed12d
      Sean Griffin 提交于
      While we query the proper columns, we go through normal handling for
      converting the value to a primitive which assumes it should use the
      table's primary key. If the association specifies a different value (and
      we know that we're working with an association), we should use the
      custom primary key instead.
      
      Fixes #18813.
      cd0ed12d
  25. 01 2月, 2015 1 次提交
    • S
      Attribute assignment and type casting has nothing to do with columns · 70ac0729
      Sean Griffin 提交于
      It's finally finished!!!!!!! The reason the Attributes API was kept
      private in 4.2 was due to some publicly visible implementation details.
      It was previously implemented by overloading `columns` and
      `columns_hash`, to make them return column objects which were modified
      with the attribute information.
      
      This meant that those methods LIED! We didn't change the database
      schema. We changed the attribute information on the class. That is
      wrong! It should be the other way around, where schema loading just
      calls the attributes API for you. And now it does!
      
      Yes, this means that there is nothing that happens in automatic schema
      loading that you couldn't manually do yourself. (There's still some
      funky cases where we hit the connection adapter that I need to handle,
      before we can turn off automatic schema detection entirely.)
      
      There were a few weird test failures caused by this that had to be
      fixed. The main source came from the fact that the attribute methods are
      now defined in terms of `attribute_names`, which has a clause like
      `return [] unless table_exists?`. I don't *think* this is an issue,
      since the only place this caused failures were in a fake adapter which
      didn't override `table_exists?`.
      
      Additionally, there were a few cases where tests were failing because a
      migration was run, but the model was not reloaded. I'm not sure why
      these started failing from this change, I might need to clear an
      additional cache in `reload_schema_from_cache`. Again, since this is not
      normal usage, and it's expected that `reset_column_information` will be
      called after the table is modified, I don't think it's a problem.
      
      Still, test failures that were unrelated to the change are worrying, and
      I need to dig into them further.
      
      Finally, I spent a lot of time debugging issues with the mutex used in
      `define_attribute_methods`. I think we can just remove that method
      entirely, and define the attribute methods *manually* in the call to
      `define_attribute`, which would simplify the code *tremendously*.
      
      Ok. now to make this damn thing public, and work on moving it up to
      Active Model.
      70ac0729
  26. 30 1月, 2015 1 次提交
  27. 29 1月, 2015 4 次提交
  28. 28 1月, 2015 3 次提交
    • S
      Remove Relation#bind_params · b06f64c3
      Sean Griffin 提交于
      `bound_attributes` is now used universally across the board, removing
      the need for the conversion layer. These changes are mostly mechanical,
      with the exception of the log subscriber. Additional, we had to
      implement `hash` on the attribute objects, so they could be used as a
      key for query caching.
      b06f64c3
    • S
      Use an `Attribute` object to represent a bind value · 6c235dd9
      Sean Griffin 提交于
      The column is primarily used for type casting, which we're trying to
      separate from the idea of a column. Since what we really need is the
      combination of a name, type, and value, let's use the object that we
      already have to represent that concept, rather than this tuple. No
      consumers of the bind values have been changed, only the producers
      (outside of tests which care too much about internals). This is
      *finally* possible since the bind values are now produced from a
      reasonable number of lcoations.
      6c235dd9
    • S
      Minor refactorings on `Relation#build_joins` · ae299dd4
      Sean Griffin 提交于
      Attempting to grok this code by refactoring it as I go through it.
      ae299dd4