1. 24 10月, 2017 13 次提交
  2. 16 10月, 2017 1 次提交
    • B
      Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong... · 99b2bf8d
      bogdanvlviv 提交于
      Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create  wrong ar_internal_metadata's data for a test database.
      
        Before:
        ```
        $ RAILS_ENV=test rails dbconsole
        > SELECT * FROM ar_internal_metadata;
        key|value|created_at|updated_at
        environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
        ```
      
        After:
        ```
        $ RAILS_ENV=test rails dbconsole
        > SELECT * FROM ar_internal_metadata;
        key|value|created_at|updated_at
        environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
        ```
      
        Fixes #26731.
      99b2bf8d
  3. 15 10月, 2017 2 次提交
    • R
      Fix longer sequence name detection for serial columns (#28339) · 8877492d
      Ryuta Kamizono 提交于
      We already found the longer sequence name, but we could not consider
      whether it was the sequence name created by serial type due to missed a
      max identifier length limitation. I've addressed the sequence name
      consideration to respect the max identifier length.
      
      Fixes #28332.
      8877492d
    • R
      MySQL: Don't lose `auto_increment: true` in the `db/schema.rb` · 9493d455
      Ryuta Kamizono 提交于
      Currently `AUTO_INCREMENT` is implicitly used in the default primary key
      definition. But `AUTO_INCREMENT` is not only used for single column
      primary key, but also for composite primary key. In that case,
      `auto_increment: true` should be dumped explicitly in the
      `db/schema.rb`.
      
      Fixes #30894.
      9493d455
  4. 14 10月, 2017 1 次提交
  5. 04 10月, 2017 1 次提交
  6. 27 9月, 2017 2 次提交
    • T
      `Postgres::OID::Range` serializes to a `Range`, quote in `Quoting` · 51b6c342
      Thomas Cannon 提交于
      PostgreSQL 9.1+ introduced range types, and Rails added support for
      using this datatype in ActiveRecord. However, the serialization of
      `PostgreSQL::OID::Range` was incomplete, because it did not properly
      quote the bounds that make up the range. A clear example of this is a
      `tsrange`.
      
      Normally, ActiveRecord quotes Date/Time objects to include the
      milliseconds. However, the way `PostgreSQL::OID::Range` serialized its
      bounds, the milliseconds were dropped. This meant that the value was
      incomplete and not equal to the submitted value.
      
      An example of normal timestamps vs. a `tsrange`. Note how the bounds
      for the range do not include their milliseconds (they were present in
      the ruby Range):
      
          UPDATE "iterations" SET "updated_at" = $1, "range" = $2 WHERE
          "iterations"."id" = $3
          [["updated_at", "2017-09-23 17:07:01.304864"],
          ["range", "[2017-09-23 00:00:00 UTC,2017-09-23 23:59:59 UTC]"],
          ["id", 1234]]
      
      `PostgreSQL::OID::Range` serialized the range by interpolating a
      string for the range, which works for most cases, but does not work
      for timestamps:
      
          def serialize(value)
            if value.is_a?(::Range)
              from = type_cast_single_for_database(value.begin)
              to = type_cast_single_for_database(value.end)
              "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}"
            else
              super
            end
          end
      
          (byebug) from = type_cast_single_for_database(value.begin)
          2010-01-01 13:30:00 UTC
      
          (byebug) to = type_cast_single_for_database(value.end)
          2011-02-02 19:30:00 UTC
      
          (byebug) "[#{from},#{to}#{value.exclude_end? ? ')' : ']'}"
          "[2010-01-01 13:30:00 UTC,2011-02-02 19:30:00 UTC)"
      
      @sgrif (the original implementer for Postgres Range support) provided
      some feedback about where the quoting should occur:
      
        Yeah, quoting at all is definitely wrong here. I'm not sure what I
        was thinking in 02579b56, but what this is doing is definitely in the
        wrong place. It should probably just be returning a range of
        subtype.serialize(value.begin) and subtype.serialize(value.end), and
        letting the adapter handle the rest.
      
      `Postgres::OID::Range` now returns a `Range` object, and
      `ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting` can now encode
      and quote a `Range`:
      
          def encode_range(range)
            "[#{type_cast(range.first)},#{type_cast(range.last)}#{range.exclude_end? ? ')' : ']'}"
          end
      
          ...
      
          encode_range(range)
          #=> "['2010-01-01 13:30:00.670277','2011-02-02 19:30:00.745125')"
      
      This commit includes tests to make sure the milliseconds are
      preserved in `tsrange` and `tstzrange` columns
      51b6c342
    • S
      Treat `Set` as an `Array` in `Relation#where` · 9cf7e349
      Sean Griffin 提交于
      I do not want to set the expectation that any enumerable object should
      behave this way, but this case in particular comes up frequently enough
      that I'm caving on this one.
      
      Fixes #30684.
      9cf7e349
  7. 21 9月, 2017 2 次提交
  8. 28 8月, 2017 1 次提交
  9. 22 8月, 2017 2 次提交
    • R
      Remove deprecated `#migration_keys` · f2099361
      Ryuta Kamizono 提交于
      f2099361
    • Y
      Automatically guess the inverse associations for STI · 30ef715d
      yui-knk 提交于
      ActiveRecord associations automatically guess the inverse associations.
      But this feature does not work correctly on assoctions for STI.
      For example, before this commit
      
      ```
      class Post < ActiveRecord::Base
        belongs_to :author
      end
      
      class SpecialPost < Post; end
      
      class Author < ActiveRecord::Base
        has_many :posts
        has_many :special_posts
      end
      ```
      
      `author.posts.first.author` works correctly, but
      `author.special_posts.first.author` does not work correctly.
      30ef715d
  10. 15 8月, 2017 2 次提交
  11. 12 8月, 2017 1 次提交
  12. 07 8月, 2017 1 次提交
  13. 01 8月, 2017 1 次提交
  14. 26 7月, 2017 2 次提交
    • M
      Avoid duplicate clauses when using #or · 110e0e1f
      Maxime Lapointe 提交于
      Condenses the clauses that are common to both sides of the OR and put them outside, before the OR
      This fix the current behavior where the number of conditions is exponential based on the number of times #or is used.
      110e0e1f
    • S
      Allow `Relation#or` to accept a relation with different `references` · ea613910
      Sean Griffin 提交于
      Note that the two relations must still have the same `includes` values
      (which is the only time `references` actually does anything). It makes
      sense for us to allow this, as `references` is called implicitly when
      passing a hash to `where`.
      
      Fixes #29411
      ea613910
  15. 25 7月, 2017 1 次提交
    • L
      Stop creating ApplicationRecord on model generation · 75ccdfed
      Lisa Ugray 提交于
      When generating models, we created ApplicationRecord in the default
      location if no file existed there.  That was annoying for people who
      moved it to somewhere else in the autoload path.  At this point, the
      vast majority of apps should have either run the upgrade script or
      generated a model since upgrading.  For those that haven't the error
      message after generating a new model should be helpful:
      
         NameError: uninitialized constant ApplicationRecord
      
      To ease friction in that case, this also adds a generator for
      ApplicationRecord.
      75ccdfed
  16. 22 7月, 2017 2 次提交
    • R
      Fix `COUNT(DISTINCT ...)` with `ORDER BY` and `LIMIT` · a265d4b2
      Ryuta Kamizono 提交于
      Since #26972, `ORDER BY` is kept if `LIMIT` is presented for
      performance. But in most SQL servers (e.g. PostgreSQL, SQL Server, etc),
      `ORDER BY` expressions must appear in select list for `SELECT DISTINCT`.
      We should not replace existing select list in that case.
      a265d4b2
    • L
      Match destroyed_by_association for has_one to has_many · cb8d8909
      Lisa Ugray 提交于
      When a has_many association is destroyed by `dependent: destroy`,
      destroyed_by_association is set to the reflection, and this can be
      checked in callbacks.  This matches that behaviour for has_one
      associations.
      cb8d8909
  17. 17 7月, 2017 2 次提交
    • S
      Allow multiparameter assigned attributes to be used with `text_field` · 1519e976
      Sean Griffin 提交于
      Between 4.2 and 5.0 the behavior of how multiparameter attributes
      interact with `_before_type_cast` changed. In 4.2 it returns the
      post-type-cast value. After 5.0, it returns the hash that gets sent to
      the type. This behavior is correct, but will cause an issue if you then
      tried to render that value in an input like `text_field` or
      `hidden_field`.
      
      In this case, we want those fields to use the post-type-cast form,
      instead of the `_before_type_cast` (the main reason it uses
      `_before_type_cast` at all is to avoid losing data when casting a
      non-numeric string to integer).
      
      I've opted to modify `came_from_user?` rather than introduce a new
      method for this as I want to avoid complicating that contract further,
      and technically the multiparameter hash didn't come from assignment, it
      was constructed internally by AR.
      
      Close #27888.
      1519e976
    • S
      Post.joins(:users) should not be affected by `User.current_scope` · 5c71000d
      Sean Griffin 提交于
      This change was introduced by #18109. The intent of that change was to
      specifically apply `unscoped`, not to allow all changes to
      `current_scope` to affect the join. The idea of allowing `current_scope`
      to affect joins is interesting and potentially more consistent, but has
      sever problems associated with it. The fact that we're specifically
      stripping out joins indicates one such problem (and potentially leads to
      invalid queries).
      
      Ultimately it's difficult to reason about what `Posts.joins(:users)`
      actually means if it's affected by `User.current_scope`, and it's
      difficult to specifically control what does or doesn't get added. If we
      were starting from scratch, I don't think I'd have `joins` be affected
      by `default_scope` either, but that's too big of a breaking change to
      make at this point.
      
      With this change, we no longer apply `current_scope` when bringing in
      joins, with the singular exception of the motivating use case which
      introduced this bug, which is providing a way to *opt-out* of having the
      default scope apply to joins.
      
      Fixes #29338.
      5c71000d
  18. 14 7月, 2017 1 次提交
  19. 12 7月, 2017 1 次提交
    • L
      Change sqlite3 boolean serialization to use 1 and 0 · 52e050ed
      Lisa Ugray 提交于
      Abstract boolean serialization has been using 't' and 'f', with MySQL
      overriding that to use 1 and 0.
      
      This has the advantage that SQLite natively recognizes 1 and 0 as true
      and false, but does not natively recognize 't' and 'f'.
      
      This change in serialization requires a migration of stored boolean data
      for SQLite databases, so it's implemented behind a configuration flag
      whose default false value is deprecated. The flag itself can be
      deprecated in a future version of Rails.  While loaded models will give
      the correct result for boolean columns without migrating old data,
      where() clauses will interact incorrectly with old data.
      
      While working in this area, also change the abstract adapter to use
      `"TRUE"` and `"FALSE"` as quoted values and `true` and `false` for
      unquoted.  These are supported by PostreSQL, and MySQL remains
      overriden.
      52e050ed
  20. 09 7月, 2017 1 次提交