1. 29 7月, 2018 1 次提交
  2. 26 2月, 2018 1 次提交
  3. 10 2月, 2018 2 次提交
  4. 29 1月, 2018 1 次提交
    • D
      Avoid extra calls to to_s · 2e8c8d60
      Daniel Colson 提交于
      With #31615 `type_for_attribute` accepts either
      a symbol as well as a string. `has_attribute?` and `attribute_alias`
      also accept either. Since these methods call `to_s` on the argument,
      we no longer need to do that at the call site.
      2e8c8d60
  5. 25 1月, 2018 1 次提交
    • R
      Fix `count(:all)` with eager loading and having an order other than the driving table · ebc09ed9
      Ryuta Kamizono 提交于
      This is a regression caused by 6beb4de7.
      
      In PostgreSQL, ORDER BY expressions must appear in SELECT list when
      using DISTINCT.
      
      When using `count(:all)` with eager loading, Active Record enforces
      DISTINCT to count the driving table records only. 6beb4de7 was caused the
      regression because `count(:all)` with DISTINCT path no longer removes
      ORDER BY.
      
      We need to ignore ORDER BY when DISTINCT is enforced, otherwise not
      always generated valid SQL for PostgreSQL.
      
      Fixes #31783.
      ebc09ed9
  6. 20 12月, 2017 1 次提交
    • R
      Fix `count(:all)` to correctly work `distinct` with custom SELECT list · c6cd9a59
      Ryuta Kamizono 提交于
      Currently `count(:all)` with `distinct` doesn't work correctly because
      SELECT list is always replaced to `*` or primary key in that case even
      if having custom SELECT list.
      
      And also, PostgreSQL has a limitation that ORDER BY expressions must
      appear in select list for SELECT DISTINCT.
      
      Therefore, we should not replace custom SELECT list when using
      `count(:all)` with `distinct`.
      
      Closes #31277.
      c6cd9a59
  7. 09 11月, 2017 4 次提交
  8. 06 11月, 2017 1 次提交
  9. 14 10月, 2017 1 次提交
  10. 09 10月, 2017 1 次提交
  11. 23 9月, 2017 1 次提交
  12. 15 8月, 2017 1 次提交
    • A
      Ensure sum honors distinct on has_many through · 566f1fd0
      Aaron Wortham 提交于
      When using a has_many through relation and then summing an attribute
      the distinct was not being used. This will ensure that when summing
      an attribute, the number is only used once when distinct has been used.
      566f1fd0
  13. 24 7月, 2017 1 次提交
    • S
      Refactor Active Record to let Arel manage bind params · 213796fb
      Sean Griffin 提交于
      A common source of bugs and code bloat within Active Record has been the
      need for us to maintain the list of bind values separately from the AST
      they're associated with. This makes any sort of AST manipulation
      incredibly difficult, as any time we want to potentially insert or
      remove an AST node, we need to traverse the entire tree to find where
      the associated bind parameters are.
      
      With this change, the bind parameters now live on the AST directly.
      Active Record does not need to know or care about them until the final
      AST traversal for SQL construction. Rather than returning just the SQL,
      the Arel collector will now return both the SQL and the bind parameters.
      At this point the connection adapter will have all the values that it
      had before.
      
      A bit of this code is janky and something I'd like to refactor later. In
      particular, I don't like how we're handling associations in the
      predicate builder, the special casing of `StatementCache::Substitute` in
      `QueryAttribute`, or generally how we're handling bind value replacement
      in the statement cache when prepared statements are disabled.
      
      This also mostly reverts #26378, as it moved all the code into a
      location that I wanted to delete.
      
      /cc @metaskills @yahonda, this change will affect the adapters
      
      Fixes #29766.
      Fixes #29804.
      Fixes #26541.
      Close #28539.
      Close #24769.
      Close #26468.
      Close #26202.
      
      There are probably other issues/PRs that can be closed because of this
      commit, but that's all I could find on the first few pages.
      213796fb
  14. 22 7月, 2017 2 次提交
  15. 20 7月, 2017 1 次提交
  16. 06 7月, 2017 1 次提交
    • E
      Skip query cache for in_batches and friends · 6658e374
      Eugene Kenny 提交于
      The `find_each`, `find_in_batches` and `in_batches` APIs usually operate
      on large numbers of records, where it's preferable not to load them all
      into memory at once.
      
      If the query cache is enabled, it will hold onto the query results until
      the end of the execution context (request/job), which means the memory
      used is still proportional to the total number of records. These queries
      are typically not repeated, so the query cache isn't desirable here.
      6658e374
  17. 02 7月, 2017 1 次提交
  18. 01 7月, 2017 1 次提交
  19. 29 6月, 2017 2 次提交
  20. 29 5月, 2017 1 次提交
  21. 05 5月, 2017 1 次提交
  22. 10 3月, 2017 1 次提交
  23. 26 2月, 2017 3 次提交
    • E
      Include selects in group query with having clause · 18125683
      Eugene Kenny 提交于
      When a grouped calculation contains a having clause that references a
      selected value, we need to include that selected value in the query.
      
      Postgres doesn't support referencing a selected value in a having
      clause, but other databases do; we can skip the test on the pg adapter
      but run it for the others.
      
      This was fixed before in 9a298a16, but
      the test coverage was lost in 5a05207d.
      The fix regressed in 6311975f and was
      removed in 97d46c17.
      18125683
    • R
      Remove useless `select_values += select_values` · 97d46c17
      Ryuta Kamizono 提交于
      `select_values` is a local variable defined at previous line.
      `select_values += select_values` is totally useless.
      97d46c17
    • R
      Suppress `DISTINCT` clause outside aggregate function · d38e5d27
      Ryuta Kamizono 提交于
      `DISTINCT` clause is applied inside aggregate function by
      `operation_over_aggregate_column` if needed. Unneeded outside aggregate
      function.
      
      ```ruby
        # Before
        author.unique_categorized_posts.count
        # => SELECT DISTINCT COUNT(DISTINCT "posts"."id") FROM "posts" INNER JOIN "categorizations" ON "posts"."id" = "categorizations"."post_id" WHERE "categorizations"."author_id" = ?  [["author_id", 2]]
      
        # After
        author.unique_categorized_posts.count
        # => SELECT COUNT(DISTINCT "posts"."id") FROM "posts" INNER JOIN "categorizations" ON "posts"."id" = "categorizations"."post_id" WHERE "categorizations"."author_id" = ?  [["author_id", 2]]
      ```
      
      Closes #27615
      d38e5d27
  24. 07 2月, 2017 2 次提交
  25. 05 1月, 2017 1 次提交
  26. 06 11月, 2016 1 次提交
  27. 04 10月, 2016 1 次提交
  28. 14 9月, 2016 1 次提交
  29. 11 9月, 2016 1 次提交
  30. 26 8月, 2016 1 次提交
  31. 16 8月, 2016 1 次提交
    • M
      Fix count which would sometimes force a DISTINCT · 0aae7806
      Maxime Lapointe 提交于
      The current behaviour of checking if there is a LEFT OUTER JOIN arel
      node to detect if we are doing eager_loading is wrong. This problem
      wasn't frequent before as only some pretty specific cases would add
      a LEFT OUTER JOIN arel node. However, the recent new feature
      left_outer_joins also add this node and made this problem happen
      frequently.
      
      Since in the perform_calculation function, we don't have access to
      eager_loading information, I had to extract the logic for the distinct
      out to the calculate method.
      
      As I was in the file for left_outer_join tests, I fixed a few that had
      bugs and I replaced some that were really weak with something that
      will catch more issues.
      
      In relation tests, the first test I changed would have failed if it
      had validated the hash returned by count instead of just checking how
      many pairs were in it. This is because this merge of join currently
      transforms the join node into an outer join node, which then made
      count do a distinct. So before this change, the return was
      {1=>1, 4=>1, 5=>1}.
      0aae7806