1. 23 12月, 2014 1 次提交
    • D
      Fixing numeric attrs when set to same negative value · 2859341c
      Daniel Fox 提交于
      This bug occurs when an attribute of an ActiveRecord model is an
      ActiveRecord::Type::Integer type or a ActiveRecord::Type::Decimal type (or any
      other type that includes the ActiveRecord::Type::Numeric module. When the value
      of the attribute is negative and is set to the same negative value, it is marked
      as changed.
      
      Take the following example of a Person model with the integer attribute age:
      
          class Person < ActiveRecord::Base
            # age          :integer(4)
          end
      
      The following will produce the error:
      
          person = Person.new(age: -1)
          person.age = -1
          person.changes
          => { "age" => [-1, -1] }
          person.age_changed?
          => true
      
      The problematic line is here:
      
          module ActiveRecord
            module Type
              module Numeric
                ...
      
                def non_numeric_string?(value)
                  # 'wibble'.to_i will give zero, we want to make sure
                  # that we aren't marking int zero to string zero as
                  # changed.
                  value.to_s !~ /\A\d+\.?\d*\z/
                end
              end
            end
          end
      
      The regex match doesn't accept numbers with a leading '-'.
      2859341c
  2. 19 12月, 2014 1 次提交
  3. 18 12月, 2014 1 次提交
    • Y
      `db:structure:load` and `db:schema:load` no longer purge the database. · 36ce0c2c
      Yves Senn 提交于
      Closes #17945
      
      `db:test:prepare` still purges the database to always keep the test
      database in a consistent state.
      
      This patch introduces new problems with `db:schema:load`. Prior
      to the introduction of foreign-keys, we could run this file against
      a non-empty database. Since every `create_table` containted the
      `force: true` option, this would recreate tables when loading the schema.
      
      However with foreign-keys in place, `force: true` wont work anymore and
      the task will crash.
      
      /cc @schneems
      36ce0c2c
  4. 11 12月, 2014 1 次提交
  5. 09 12月, 2014 1 次提交
  6. 05 12月, 2014 2 次提交
  7. 04 12月, 2014 3 次提交
  8. 02 12月, 2014 1 次提交
  9. 29 11月, 2014 1 次提交
  10. 26 11月, 2014 2 次提交
    • J
      Active Record change log pass [skip ci] · 35c5f47d
      Jon Atack 提交于
      35c5f47d
    • Y
      bring back `db:test:prepare`. · 5c449553
      Yves Senn 提交于
      This reverts deprecations added in #13528.
      The task is brought back for two reasons:
        1. Give plugins a way to hook into the test database initialization process
        2. Give the user a way to force a test database synchronization
      
      While `test:prepare` is still a dependency of every test task, `db:test:prepare`
      no longer hooks into it. This means that `test:prepare` runs before the schema
      is synchronized. Plugins, which insert data can now hook into `db:test:prepare`.
      
      The automatic schema maintenance can't detect when a migration is rolled-back,
      modified and reapplied. In this case the user has to fall back to `db:test:prepare`
      to force the synchronization to happen.
      5c449553
  11. 23 11月, 2014 2 次提交
  12. 21 11月, 2014 2 次提交
  13. 11 11月, 2014 1 次提交
  14. 05 11月, 2014 1 次提交
  15. 03 11月, 2014 2 次提交
  16. 02 11月, 2014 1 次提交
    • S
      Use bind values for joined tables in where statements · 10f75af9
      Sean Griffin 提交于
      In practical terms, this allows serialized columns and tz aware columns
      to be used in wheres that go through joins, where they previously would
      not behave correctly. Internally, this removes 1/3 of the cases where we
      rely on Arel to perform type casting for us.
      
      There were two non-obvious changes required for this. `update_all` on
      relation was merging its bind values with arel's in the wrong order.
      Additionally, through associations were assuming there would be no bind
      parameters in the preloader (presumably because the where would always
      be part of a join)
      
      [Melanie Gilman & Sean Griffin]
      10f75af9
  17. 29 10月, 2014 1 次提交
  18. 25 10月, 2014 1 次提交
    • D
      Use type column first in multi-column indexes · 9cdd0a1f
      Derek Prior 提交于
      `add_reference` can very helpfully add a multi-column index when you use
      it to add a polymorphic reference. However, the first column in the
      index is the `id` column, which is less than ideal.
      
      The [PostgreSQL docs][1] say:
      > A multicolumn B-tree index can be used with query conditions that
      > involve any subset of the index's columns, but the index is most
      > efficient when there are constraints on the leading (leftmost)
      > columns.
      
      The [MySQL docs][2] say:
      > MySQL can use multiple-column indexes for queries that test all the
      > columns in the index, or queries that test just the first column, the
      > first two columns, the first three columns, and so on. If you specify
      > the columns in the right order in the index definition, a single
      > composite index can speed up several kinds of queries on the same
      > table.
      
      In a polymorphic relationship, the type column is much more likely to be
      useful as the first column in an index than the id column. That is, I'm
      more likely to query on type without an id than I am to query on id
      without a type.
      
      [1]: http://www.postgresql.org/docs/9.3/static/indexes-multicolumn.html
      [2]: http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html
      9cdd0a1f
  19. 20 10月, 2014 2 次提交
  20. 16 10月, 2014 1 次提交
    • Y
      AR::UnknownAttributeError should include the class name of a record · 074880c4
      Yuki Nishijima 提交于
      This would be helpful if 2 models have an attribute that has a similar
      name to the other. e.g:
      
      before:
      
          User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"])
          # => ActiveRecord::UnknownAttributeError: unknown attribute: name
      
      after:
      
          User.new(name: "Yuki Nishijima", projects_attributes: [name: "kaminari"])
          # => ActiveRecord::UnknownAttributeError: unknown attribute on User: name
      074880c4
  21. 13 10月, 2014 1 次提交
    • A
      Autosave callbacks shouldn't be `after_save` · 719d52db
      Agis- 提交于
      068f092c registered autosave callbacks
      as `after_save` callbacks. This caused the regression described in #17209.
      
      Autosave callbacks should be registered as `after_update` and
      `after_create` callbacks, just like before.
      
      This is a partial revert of 068f092c.
      
      Fixes #17209.
      719d52db
  22. 06 10月, 2014 1 次提交
  23. 03 10月, 2014 1 次提交
    • B
      Fix that a collection proxy could be cached before the save of the owner,... · cc405496
      Ben Woosley 提交于
      Fix that a collection proxy could be cached before the save of the owner, resulting in an invalid proxy lacking the owner’s id.
      
      Absent this fix calls like: owner.association.update_all to behave unexpectedly because they try to act on association objects where
      owner_id is null.
      
      more evidence here: https://gist.github.com/Empact/5865555
      ```
      Active Record 3.2.13
      -- create_table(:firms, {:force=>true})
         -> 0.1371s
      -- create_table(:clients, {:force=>true})
         -> 0.0005s
      1 clients. 1 expected.
      1 clients updated. 1 expected.
      ```
      
      ```
      Active Record 4.0.0
      -- create_table(:firms, {:force=>true})
         -> 0.1606s
      -- create_table(:clients, {:force=>true})
         -> 0.0004s
      1 clients. 1 expected.
      0 clients updated. 1 expected.
      ```
      cc405496
  24. 27 9月, 2014 1 次提交
  25. 23 9月, 2014 3 次提交
  26. 20 9月, 2014 1 次提交
  27. 19 9月, 2014 1 次提交
  28. 17 9月, 2014 3 次提交