1. 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
  2. 24 9月, 2015 1 次提交
  3. 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
  4. 09 9月, 2015 1 次提交
  5. 07 9月, 2015 1 次提交
  6. 06 9月, 2015 1 次提交
  7. 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
  8. 13 8月, 2015 1 次提交
  9. 08 8月, 2015 1 次提交
  10. 23 7月, 2015 1 次提交
  11. 22 7月, 2015 2 次提交
  12. 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
  13. 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
  14. 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
  15. 25 6月, 2015 1 次提交
  16. 12 6月, 2015 1 次提交
  17. 05 6月, 2015 1 次提交
  18. 11 5月, 2015 1 次提交
    • A
      allow setting of a demodulized class name when using STI · cbd66b43
      Alex Robbin 提交于
      If your STI class looks like this:
      
      ```ruby
      class Company < ActiveRecord::Base
        self.store_full_sti_class = false
      
        class GoodCo < Company
        end
      
        class BadCo < Company
        end
      end
      ```
      
      The expectation (which is valid) is that the `type` in the database is saved as
      `GoodCo` or `BadCo`. However, another expectation should be that setting `type`
      to `GoodCo` would correctly instantiate the object as a `Company::GoodCo`. That
      second expectation is what this should fix.
      cbd66b43
  19. 09 5月, 2015 1 次提交
  20. 16 4月, 2015 1 次提交
  21. 09 4月, 2015 1 次提交
  22. 07 4月, 2015 1 次提交
    • T
      Require explicit counter_cache option for has_many · e0cb21f5
      Tristan Gamilis 提交于
      Previously has_many associations assumed a counter_cache was to be used
      based on the presence of an appropriately named column. This is
      inconsistent, since the inverse belongs_to association will not make
      this assumption. See issues #19042 #8446.
      This commit checks for the presence of the counter_cache key in the
      options of either the has_many or belongs_to association as well as
      ensuring that the *_count column is present.
      e0cb21f5
  23. 15 3月, 2015 1 次提交
    • E
      Fix leaky chain on polymorphic association · 51660f01
      eileencodes 提交于
      If there was a polymorphic hm:t association with a scope AND second
      non-scoped hm:t association on a model the polymorphic scope would leak
      through into the call for the non-polymorhic hm:t association.
      
      This would only break if `hotel.drink_designers` was called before
      `hotel.recipes`. If `hotel.recipes` was called first there would be
      no problem with the SQL.
      
      Before (employable_type should not be here):
      ```
      SELECT COUNT(*) FROM "drink_designers" INNER JOIN "chefs" ON
      "drink_designers"."id" = "chefs"."employable_id" INNER JOIN
      "departments" ON "chefs"."department_id" = "departments"."id" WHERE
      "departments"."hotel_id" = ? AND "chefs"."employable_type" = ?
      [["hotel_id", 1], ["employable_type", "DrinkDesigner"]]
      ```
      
      After:
      ```
      SELECT COUNT(*) FROM "recipes" INNER JOIN "chefs" ON "recipes"."chef_id"
      = "chefs"."id" INNER JOIN "departments" ON "chefs"."department_id" =
      "departments"."id" WHERE "departments"."hotel_id" = ?  [["hotel_id", 1]]
      ```
      
      From the SQL you can see that `employable_type` was leaking through when
      calling recipes. The solution is to dup the chain of the polymorphic
      association so it doesn't get cached. Additionally, this follows
      `scope_chain` which dup's the `source_reflection`'s `scope_chain`.
      
      This required another model/table/relationship because the leak only
      happens on a hm:t polymorphic that's called before another hm:t on the
      same model.
      
      I am specifically testing the SQL here instead of the number of records
      becasue the test could pass if there was 1 drink designer recipe for the
      drink designer chef even though the `employable_type` was leaking through.
      This needs to specifically check that `employable_type` is not in the SQL
      statement.
      51660f01
  24. 19 2月, 2015 2 次提交
  25. 18 2月, 2015 1 次提交
  26. 30 1月, 2015 1 次提交
  27. 29 1月, 2015 2 次提交
  28. 27 1月, 2015 1 次提交
    • S
      Improve consistency of counter caches updating in memory · 1152219f
      Sean Griffin 提交于
      When we made sure that the counter gets updated in memory, we only did
      it on the has many side. The has many side only does the update if the
      belongs to cannot. The belongs to side was updated to update the counter
      cache (if it is able). This means that we need to check if the
      belongs_to is able to update in memory on the has_many side.
      
      We also found an inconsistency where the reflection names were used to
      grab the association which should update the counter cache. Since
      reflection names are now strings, this means it was using a different
      instance than the one which would have the inverse instance set.
      
      Fixes #18689
      
      [Sean Griffin & anthonynavarre]
      1152219f
  29. 15 1月, 2015 1 次提交
    • V
      Fixes #18492 · 4ae59ebe
      Vipul A M 提交于
      - Add check for not deleting previously created fixtures, to overcome sti fixtures from multiple files
      - Added fixtures and fixtures test to verify the same
      
      - Fixed wrong fixtures duplicating data insertion in same table
      4ae59ebe
  30. 05 1月, 2015 2 次提交
  31. 03 1月, 2015 1 次提交
    • C
      Deprecate `false` as the way to halt AR callbacks · bb78af73
      claudiob 提交于
      Before this commit, returning `false` in an ActiveRecord `before_` callback
      such as `before_create` would halt the callback chain.
      
      After this commit, the behavior is deprecated: will still work until
      the next release of Rails but will also display a deprecation warning.
      
      The preferred way to halt a callback chain is to explicitly `throw(:abort)`.
      bb78af73
  32. 31 12月, 2014 1 次提交
    • R
      Fix error message when trying to create an associated record · 04852b87
      Rafael Mendonça França 提交于
      This error only happens when the foreign key is missing.
      
      Before this fix the following exception was being raised:
      
          NoMethodError: undefined method `val' for #<Arel::Nodes::BindParam:0x007fc64d19c218>
      
      Now the message is:
      
          ActiveRecord::UnknownAttributeError: unknown attribute 'foreign_key' for Model.
      04852b87
  33. 30 12月, 2014 2 次提交
    • Y
      AR specific length validator to respect `marked_for_destruction`. · 2b122881
      Yves Senn 提交于
      Closes #7247.
      
      Conflicts:
      	activerecord/CHANGELOG.md
      	activerecord/test/models/owner.rb
      2b122881
    • S
      Remove all cases of manuallly wrapping `Arel::Nodes::Quoted` · f916aa24
      Sean Griffin 提交于
      This is no longer required now that we are injecting a type caster
      object into the Arel table, with the exception of uniqueness
      validations. Since it calls `ConnectionAdapter#type_cast`, the value has
      already been cast for the database. We don't want Arel to attempt to
      cast it further, so we need to continue wrapping it in a quoted node.
      This can potentially go away when this validator is refactored to make
      better use of `where` or the predicate builder.
      f916aa24
  34. 27 12月, 2014 1 次提交
    • S
      Inform Arel we don't need additional type casting in tests · de0cfd27
      Sean Griffin 提交于
      Part of the larger refactoring to remove type casting from Arel. We can
      inform it that we already have the right type by wrapping the value in
      an `Arel::Nodes::Quoted`. This commit can be reverted when we have
      removed type casting from Arel in Rail 5.1
      de0cfd27