1. 31 5月, 2016 1 次提交
    • S
      Ensure hashes can be passed to attributes using `composed_of` · ff4986b9
      Sean Griffin 提交于
      This behavior was broken by 36e9be85. When the value is assigned
      directly, either through mass assignment or directly assigning a hash,
      the hash gets passed through to this writer method directly. While this
      is intended to handle certain cases, when an explicit converter has been
      provided, we should continue to use that instead. The positioning of the
      added guard caused the new behavior to override that case.
      
      Fixes #25210
      ff4986b9
  2. 06 4月, 2016 1 次提交
    • L
      Fix undefined method `owners' for NullPreloader:Class · cb4f6875
      Ladislav Smola 提交于
      * Fix undefined method `owners' for NullPreloader:Class
      
      Fixing undefined method `owners' for
      ActiveRecord::Associations::Preloader::NullPreloader:Class
      
      * Use Ruby 1.9 hash format
      
      Use Ruby 1.9 hash format
      
      #24192
      
      [Rafael Mendonça França + Ladislav Smola]
      cb4f6875
  3. 12 3月, 2016 1 次提交
    • R
      Fix `warning: method redefined; discarding old female` · 7c61f5c2
      Ryuta Kamizono 提交于
      ```
      $ ARCONN=mysql2 be ruby -w -Itest test/cases/scoping/default_scoping_test.rb
      Using mysql2
      /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: method redefined; discarding old female
      /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: previous definition of female was here
      /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: method redefined; discarding old male
      /Users/kamipo/src/github.com/rails/rails/activerecord/lib/active_record/scoping/named.rb:158: warning: previous definition of male was here
      ```
      7c61f5c2
  4. 08 3月, 2016 1 次提交
  5. 03 3月, 2016 1 次提交
  6. 25 2月, 2016 1 次提交
    • E
      Ensure suppressor runs before validations · 73f8c166
      eileencodes 提交于
      I ran into an issue where validations on a suppressed record were
      causing validation errors to be thrown on a record that was never going
      to be saved.
      
      There isn't a reason to run the validations on a record that doesn't
      matter.
      
      This change moves the suppressor up the chain to be run on the `save` or
      `save!` in the validations rather than in persistence. The issue with
      running it when we hit persistence is that the validations are run
      first, then we hit persistance, and then we hit the suppressor. The
      suppressor comes first.
      
      The change to the test was required since I added the
      `validates_presence_of` validations. Adding this alone was enough to
      demonstrate the issue. I added a new test to demonstrate the new
      behavior is explict.
      73f8c166
  7. 18 2月, 2016 1 次提交
    • J
      Fix issue #23625 · 55385c8a
      Jon Moss 提交于
      This resolves a bug where if the primary key used is not `id` (ex:
      `uuid`), and has a `validates_uniqueness_of` in the model, a uniqueness error
      would be raised. This is a partial revert of commit `119b9181`, which introduced this behavior.
      55385c8a
  8. 17 2月, 2016 1 次提交
    • P
      Fixed `where` for polymorphic associations when passed an array containing different types. · 359adaed
      Philippe Huibonhoa 提交于
      When passing in an array of different types of objects to `where`, it would only take into account the class of the first object in the array.
      
          PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
      	# => SELECT "price_estimates".* FROM "price_estimates"
               WHERE ("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" IN (1, 2))
      
      This is fixed to properly look for any records matching both type and id:
      
          PriceEstimate.where(estimate_of: [Treasure.find(1), Car.find(2)])
          # => SELECT "price_estimates".* FROM "price_estimates"
               WHERE (("price_estimates"."estimate_of_type" = 'Treasure' AND "price_estimates"."estimate_of_id" = 1)
               OR ("price_estimates"."estimate_of_type" = 'Car' AND "price_estimates"."estimate_of_id" = 2))
      359adaed
  9. 03 2月, 2016 1 次提交
  10. 31 1月, 2016 1 次提交
  11. 25 1月, 2016 1 次提交
  12. 23 1月, 2016 1 次提交
    • S
      Use the database type to deserialize enum · 67c17190
      Sean Griffin 提交于
      This fixes incorrect assumptions made by e991c7b8 that we can assume the
      DB is already casting the value for us. The enum type needs additional
      information to perform casting, and needs a subtype.
      
      I've opted not to call `super` in `cast`, as we have a known set of
      types which we accept there, and the subtype likely doesn't accept them
      (symbol -> integer doesn't make sense)
      
      Close #23190
      67c17190
  13. 15 1月, 2016 1 次提交
  14. 12 1月, 2016 1 次提交
    • M
      Skip the STI condition when evaluating a default scope · 5c6d3653
      Matthew Draper 提交于
      Given a default_scope on a parent of the current class, where that
      parent is not the base class, the parent's STI condition would become
      attached to the evaluated default scope, and then override the child's
      own STI condition.
      
      Instead, we can treat the STI condition as though it is a default scope,
      and skip it in this situation: the scope will be merged into the base
      relation, which already contains the correct STI condition.
      
      Fixes #22426.
      5c6d3653
  15. 10 1月, 2016 1 次提交
  16. 23 11月, 2015 1 次提交
  17. 16 11月, 2015 1 次提交
    • Y
      Except keys of `build_record`'s argument from `create_scope` in initialize_attributes · 817c1825
      yui-knk 提交于
      If argument of `build_record` has key and value which is same as
      default value of database, we should also except the key from
      `create_scope` in `initialize_attributes`.
      Because at first `build_record` initialize record object with argument
      of `build_record`, then assign attributes derived from Association's scope.
      In this case `record.changed` does not include the key, which value is
      same as default value of database, so we should add the key to except list.
      
      Fix #21893.
      817c1825
  18. 30 10月, 2015 1 次提交
    • S
      Ensure `has_and_belongs_to_many` works with `belongs_to_required_by_default` · 21a386bb
      Sean Griffin 提交于
      Before this commit, if
      `ActiveRecord::Base.belongs_to_required_by_default` is set to `true`,
      then creating a record through `has_and_belongs_to_many` fails with the
      cryptic error message `Left side must exist`. This is because
      `inverse_of` isn't working properly in this case, presumably since we're
      doing trickery with anonymous classes in the middle.
      
      Rather than following this rabbit hole to try and get `inverse_of` to
      work in a case that we know is not publicly supported, we can just turn
      off this validation to match the behavior of 4.2 and earlier.
      21a386bb
  19. 27 10月, 2015 2 次提交
  20. 22 10月, 2015 1 次提交
    • R
      Refactor Calculations#execute_grouped_calculation and clean AR test case · 4f21d42f
      Rafael Sales 提交于
      * When tried to use `Company#accounts` test/models/company.rb I got:
      
      ```
      ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column:
      accounts.company_id: SELECT COUNT(*) AS count_all, "companies"."firm_id"
      AS companies_firm_id FROM "companies" INNER JOIN "accounts" ON
      "accounts"."company_id" = "companies"."id" GROUP BY "companies"."firm_id"
      ```
      
      * The refactor on Calculations class was just to simplify the code
      4f21d42f
  21. 21 10月, 2015 1 次提交
  22. 02 10月, 2015 1 次提交
  23. 27 9月, 2015 1 次提交
    • E
      Fix regression in inverse_of on through associations · ee824c88
      eileencodes 提交于
      `inverse_of` on through associations was accidently removed/caused to
      stop working in commit f8d2899d which was part of a refactoring on
      `ThroughReflection`.
      
      To fix we moved `inverse_of` and `check_validity_of_inverse!` to the
      `AbstractReflection` so it's available to the `ThroughReflection`
      without having to dup any methods. We then need to delegate `inverse_name`
      method in `ThroughReflection`. `inverse_name` can't be moved to
      `AbstractReflection` without moving methods that set the instance
      variable `@automatic_inverse_of`.
      
      This adds a test that ensures that `inverse_of` on a `ThroughReflection`
      returns the correct class name, and the correct record for the inverse
      relationship.
      
      Fixes #21692
      ee824c88
  24. 24 9月, 2015 1 次提交
  25. 23 9月, 2015 1 次提交
    • Y
      introduce `conn.data_source_exists?` and `conn.data_sources`. · 152b85f0
      Yves Senn 提交于
      These new methods are used from the Active Record model layer to
      determine which relations are viable to back a model. These new methods
      allow us to change `conn.tables` in the future to only return tables and
      no views. Same for `conn.table_exists?`.
      
      The goal is to provide the following introspection methods on the
      connection:
      
      * `tables`
      * `table_exists?`
      * `views`
      * `view_exists?`
      * `data_sources` (views + tables)
      * `data_source_exists?` (views + tables)
      152b85f0
  26. 09 9月, 2015 1 次提交
  27. 07 9月, 2015 1 次提交
  28. 06 9月, 2015 1 次提交
  29. 24 8月, 2015 1 次提交
    • A
      Only nullify persisted has_one target associations · 19b168e6
      Agis- 提交于
      Since after 87d1aba3 `dependent: :destroy` callbacks on has_one
      assocations run *after* destroy, it is possible that a nullification is
      attempted on an already destroyed target:
      
          class Car < ActiveRecord::Base
            has_one :engine, dependent: :nullify
          end
      
          class Engine < ActiveRecord::Base
            belongs_to :car, dependent: :destroy
          end
      
          > car = Car.create!
          > engine = Engine.create!(car: car)
          > engine.destroy! # => ActiveRecord::ActiveRecordError: cannot update a
          >   destroyed record
      
      In the above case, `engine.destroy!` deletes `engine` and *then* triggers the
      deletion of `car`, which in turn triggers a nullification of `engine.car_id`.
      However, `engine` is already destroyed at that point.
      
      Fixes #21223.
      19b168e6
  30. 13 8月, 2015 1 次提交
  31. 08 8月, 2015 1 次提交
  32. 23 7月, 2015 1 次提交
  33. 22 7月, 2015 2 次提交
  34. 20 7月, 2015 2 次提交
    • S
      Correctly ignore `mark_for_destruction` without `autosave` · c0ef95a1
      Sean Griffin 提交于
      As per the docs, `mark_for_destruction` should do nothing if `autosave`
      is not set to true. We normally persist associations on a record no
      matter what if the record is a new record, but we were always skipping
      records which were `marked_for_destruction?`.
      
      Fixes #20882
      c0ef95a1
    • S
      Fix counter_cache for polymorphic associations · 0ed096dd
      Stefan Kanev 提交于
      Also removes a false positive test that depends on the fixed bug:
      
      At this time, counter_cache does not work with polymorphic relationships
      (which is a bug). The test was added to make sure that no
      StaleObjectError is raised when the car is destroyed. No such error is
      currently raised because the lock version is not incremented by
      appending a wheel to the car.
      
      Furthermore, `assert_difference` succeeds because `car.wheels.count`
      does not check the counter cache, but the collection size. The test will
      fail if it is replaced with `car.wheels_count || 0`.
      0ed096dd
  35. 18 7月, 2015 1 次提交
    • S
      Ensure cyclic associations w/ autosave don't cause duplicate errors · 7550f0a0
      Sean Griffin 提交于
      This code is so fucked. Things that cause this bug not to replicate:
      
      - Defining the validation before the association (we end up calling
        `uniq!` on the errors in the autosave validation)
      - Adding `accepts_nested_attributes_for` (I have no clue why. The only
        thing it does that should affect this is adds `autosave: true` to the
        inverse reflection, and doing that manually doesn't fix this).
      
      This solution is a hack, and I'm almost certain there's a better way to
      go about it, but this shouldn't cause a huge hit on validation times,
      and is the simplest way to get it done.
      
      Fixes #20874.
      7550f0a0
  36. 08 7月, 2015 1 次提交
    • R
      Fix regression caused by a01d164b · 1b4399df
      Rafael Mendonça França 提交于
      When preload is used in a default scope the preload_values were
      returning nested arrays and causing the preloader to fail because it
      doesn't know how to deal with nested arrays. So before calling preload!
      we need to splat the arguments.
      
      This is not needed to includes because it flatten its arguments.
      1b4399df
  37. 25 6月, 2015 1 次提交