1. 13 5月, 2020 7 次提交
    • R
      Fix `pluck` to correctly type cast same column names and association columns · 71f0df94
      Ryuta Kamizono 提交于
      That issues are caused by using only the model's cast types on the
      relation.
      To fix that issues, use the attribute's type caster takes precedence
      over the model's cast types on the relation.
      
      Fixes #35232.
      Fixes #36042.
      Fixes #37484.
      71f0df94
    • R
      Test to reference through association in `where` · ed29afcc
      Ryuta Kamizono 提交于
      ed29afcc
    • R
      Fix type casting aggregated values on association's attributes · 5f59eac2
      Ryuta Kamizono 提交于
      Follow up of #39255.
      
      Previously aggregation functions only use the model's attribute types on
      the relation for type cast, this will be looking up association's
      attribute and type caster if a column name is table name qualified.
      
      Fixes #39248.
      5f59eac2
    • E
      Use binread instead of setting file mode manually · 96a1a2a3
      Eugene Kenny 提交于
      Followup to b3102205.
      96a1a2a3
    • J
      Avoid confliting Kernel-named scopes on Relation · 1b773bca
      John Hawthorn 提交于
      A previous change made singleton methods eagerly define their relation
      methods if it shared a name with a method on Kernel. This caused issues
      with a few methods which were both defined on Kernel and on
      AcitveRecord::Relation.
      
      This commit avoids defining the method if it exists on AR::Relation.
      1b773bca
    • E
      Remove implementation of unchecked_serialize · 6833bf4d
      eileencodes 提交于
      Since we're checking `serializable?` in the new `HomogeneousIn`
      `serialize` will no longer raise an exception. We implemented
      `unchecked_serialize` to avoid raising in these cases, but with some of
      our refactoring we no longer need it.
      
      I discovered this while trying to fix a query in our application that
      was not properly serializing binary columns. I discovered that in at
      least 2 of our active model types we were not calling the correct
      serialization. Since `serialize` wasn't aliased to `unchecked_serialize`
      in `ActiveModel::Type::Binary` and `ActiveModel::Type::Boolean` (I
      didn't check others but pretty sure all the AM Types are broken) the SQL
      was being treated as a `String` and not the correct type.
      
      This caused Rails to incorrectly query by string values. This is
      problematic for columns storing binary data like our emoji columns at
      GitHub. The test added here is an example of how the Binary type was
      broken previously. The SQL should be using the hex values, not the
      string value of "🥦" or other emoji.
      
      We still have the problem `unchecked_serialize` was supposed to fix -
      that `serialize` shouldn't validate data, just convert it. We'll be
      fixing that in a followup PR so for now we should use `serialize` so we
      know all the values are going through the right serialization for their
      SQL.
      6833bf4d
    • R
      Fix `minimum` and `maximum` on time zone aware attributes · 11751b2e
      Ryuta Kamizono 提交于
      This is the opposite direction of #39039.
      
      #39111 fixes `minimum` and `maximum` on date columns with type casting
      by column type on the database. But column type has no information for
      time zone aware attributes, it means that attribute type should always
      be precedence over column type. I've realized that fact in the related
      issue report #39248.
      
      I've reverted the expectation of #39039, to make time zone aware
      attributes works.
      11751b2e
  2. 12 5月, 2020 1 次提交
  3. 11 5月, 2020 1 次提交
    • Y
      Address `InnerJoinAssociationTest#test_eager_load_with_string_joins` failure with mysql2 · 950a453d
      Yasuo Honda 提交于
      `ReadOnlyTest#test_field_named_field` performs implicit commit the transaction by `ReadOnlyTest#setup`
      because of the MySQL database behavior.
      
      This commit addresses the failure at https://buildkite.com/rails/rails/builds/68962#68213887-1cef-4f76-9c95-aebc8799c806
      Here are minimum steps to reproduce:
      
      ```ruby
      % ARCONN=mysql2 bin/test test/cases/readonly_test.rb test/cases/dirty_test.rb test/cases/associations/inner_join_association_test.rb \
      -n "/^(?:ReadOnlyTest#(?:test_has_many_with_through_is_not_implicitly_marked_readonly)|DirtyTest#(?:test_field_named_field)|InnerJoinAssociationTest#(?:test_eager_load_with_string_joins))$/" --seed 50855
      Using mysql2
      Run options: -n "/^(?:ReadOnlyTest#(?:test_has_many_with_through_is_not_implicitly_marked_readonly)|DirtyTest#(?:test_field_named_field)|InnerJoinAssociationTest#(?:test_eager_load_with_string_joins))$/" --seed 50855
      
      ..F
      
      Failure:
      InnerJoinAssociationTest#test_eager_load_with_string_joins [/Users/yahonda/src/github.com/rails/rails/activerecord/test/cases/associations/inner_join_association_test.rb:87]:
      Expected: 3
        Actual: 4
      
      bin/test test/cases/associations/inner_join_association_test.rb:82
      
      Finished in 0.114674s, 26.1611 runs/s, 26.1611 assertions/s.
      3 runs, 3 assertions, 1 failures, 0 errors, 0 skips
      ```
      
      References:
      - "13.3.3 Statements That Cause an Implicit Commit"
      https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html
      950a453d
  4. 10 5月, 2020 6 次提交
  5. 09 5月, 2020 2 次提交
  6. 08 5月, 2020 1 次提交
  7. 07 5月, 2020 4 次提交
    • R
      Fix the result of aggregations to maintain duplicated "group by" fields · 82b66fe4
      Ryuta Kamizono 提交于
      Actually that result is odd and hard to predictable result to me, but we
      should not change the public behavior without deprecation cycle.
      
      I had not intended to break any apps, so I've restored the behavior.
      
      Fixes #39171.
      82b66fe4
    • R
      Allow `unscope` to be aware of table name qualified values · 5136277f
      Ryuta Kamizono 提交于
      It is possible to unscope only the column in the specified table.
      
      ```ruby
      posts = Post.joins(:comments).group(:"posts.hidden")
      posts = posts.where("posts.hidden": false, "comments.hidden": false)
      
      posts.count
      # => { false => 10 }
      
      # unscope both hidden columns
      posts.unscope(where: :hidden).count
      # => { false => 11, true => 1 }
      
      # unscope only comments.hidden column
      posts.unscope(where: :"comments.hidden").count
      # => { false => 11 }
      ```
      Co-authored-by: NSlava Korolev <korolvs@gmail.com>
      5136277f
    • J
      Add DATE_FORMATS[:inspect] · 2b38bf68
      Jonathan Hefner 提交于
      Follow-up to #39147 and #39168.
      
      By adding a new purpose-specific format, we avoid potential pitfalls
      from concatenating format strings.  We also save a String allocation per
      Time attribute per inspect.
      
      The new format also includes a time zone offset for more introspective
      inspection.
      2b38bf68
    • A
      Don't attempt to add a string to a lambda · 38121340
      Adam Hess 提交于
      DATE_FORMATS can be either a format string or a lambda we don't want to attempt to concat them with a string if we are in the lambda case
      38121340
  8. 06 5月, 2020 6 次提交
  9. 05 5月, 2020 6 次提交
  10. 04 5月, 2020 2 次提交
  11. 03 5月, 2020 2 次提交
  12. 02 5月, 2020 2 次提交