aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder
Commit message (Collapse)AuthorAgeFilesLines
* Confirm a record has not already been destroyed before decrementingBen Tucker2013-05-061-1/+3
| | | | | | | | | counter cache At present, calling destroy multiple times on the same record results in the belongs_to counter cache being decremented multiple times. With this change the record is checked for whether it is already destroyed prior to decrementing the counter cache.
* Lookup the class at runtime, not when the association is builtAndrew White2013-04-241-2/+2
| | | | | | | | | Trying to lookup the parent class when the association is being built runs the risk of generating uninitialized constant errors because classes haven't been fully defined yet. To work around this we look up the class at runtime through the `association` method. Fixes #10197.
* Revert "Revert "`belongs_to :touch` behavior now touches old association ↵Andrew White2013-04-241-1/+12
| | | | | | | | | when transitioning to new association" until a proper fix is found for #10197" This reverts commit 7389df139a35436f00876c96d20e81ba23c93f0a. Conflicts: activerecord/test/cases/timestamp_test.rb
* Revert "`belongs_to :touch` behavior now touches old association when ↵David Heinemeier Hansson2013-04-231-12/+1
| | | | transitioning to new association" until a proper fix is found for #10197
* Update counter cache when pushing into associationMatthew Robertson2013-04-211-3/+4
| | | | | | | | | | | | | | | | This commit fixes a regression bug in which counter_cache columns were not being updated correctly when newly created records were being pushed into an assocation. EG: # this was fine @post.comment.create! # this was fine @comment = Comment.first @post.comments << @comment # this would not update counters @post.comments << Comment.create!
* Avoid an attempt to fetch old record when id was not present in touch callbackCarlos Antonio da Silva2013-04-041-7/+7
|
* Use the correct pk field from the reflected class to find the old recordCarlos Antonio da Silva2013-04-041-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | The implementation was using the source class foreign key field instead of the reflected primary key one to find the old record. For instance, for this scenario class Bulb < ActiveRecord::Base belongs_to :car, :touch => true end class Car < ActiveRecord::Base has_many :bulbs end the current implementation was trying to do this query: Car.where(car_id: X).first where we should be doing this query: Car.where(id: X).first This should hopefully fix the build.
* Use inspect when writing the foreign key from the reflectionAndrew White2013-04-051-2/+2
| | | | | | If we don't use inspect inside the class_eval block then the foreign key is written without quotes causing us to fetch the foreign key value and not the column name.
* Merge pull request #9141 from adamgamble/issue-9091David Heinemeier Hansson2013-04-031-0/+10
|\ | | | | belongs_to :touch should touch old record when transitioning.
| * Modifies belong_to touch callback to touch old associations also #9091Adam Gamble2013-03-141-0/+10
| |
* | Update other counter caches on destroyIan Young2013-03-201-1/+1
| |
* | If a counter_cache is defined, then using update_attributes and changingJohn Wang2013-03-151-0/+20
|/ | | | | the primary key on an association will make sure that the corresponding counter on the association is changed properly. Fixes #9722.
* Fix touching an invalid parent record for belongs_toOlek Janiszewski2013-02-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | If the parent of a `belongs_to` record fails to be saved due to validation errors, `touch` will be called on a new record, which causes an exception (see https://github.com/rails/rails/pull/9320). Example: class Owner < ActiveRecord::Base validates_presence_of :name end class Pet < ActiveRecord::Base belongs_to :owner, touch: true end pet = Pet.new(owner: Owner.new) # Before, this line would raise ActiveRecord::ActiveRecordError # "can not touch on a new record object" pet.save
* Undeprecate the :extend optionJon Leighton2013-01-181-1/+2
| | | | | | | Suggested by @dhh. It doesn't affect the generated SQL, so seems reasonable to continue to allow it as an association option.
* Ensure that associations have a symbol argument.Steve Klabnik2012-11-281-0/+2
| | | | Fixes #7418.
* Merge pull request #8116 from senny/7993_configure_counter_cache_for_has_manyJon Leighton2012-11-091-1/+1
|\ | | | | :counter_cache option for to support custom named counter caches
| * :counter_cache option for to support custom named counter caches. Closes #7993Yves Senn2012-11-041-1/+1
| |
* | adding requires for constant dependenciesAaron Patterson2012-11-071-0/+3
|/
* Use method compilation for association methodsJon Leighton2012-08-105-64/+62
| | | | | | | | | Method compilation provides better performance and I think the code comes out cleaner as well. A knock on effect is that methods that get redefined produce warnings. I think this is a good thing. I had to deal with a bunch of warnings coming from our tests, though.
* DRY up handling of dependent optionJon Leighton2012-08-105-63/+22
|
* Unprivatise all the thingsJon Leighton2012-08-107-170/+156
| | | | | | Well, not all of them, but some of them. I don't think there's much reason for these methods to be private.
* move dependency logic out of generated methodsJon Leighton2012-08-104-65/+19
|
* Clean up dependent option validation.Jon Leighton2012-08-104-14/+7
| | | | | We don't need the complexity of to_sentence, and it shouldn't be a bang method.
* Remove the dependent_restrict_raises option.Jon Leighton2012-08-103-23/+22
| | | | | | | | | | | | | | | It's not really a good idea to have this as a global config option. We should allow people to specify the behaviour per association. There will now be two new values: * :dependent => :restrict_with_exception implements the current behaviour of :restrict. :restrict itself is deprecated in favour of :restrict_with_exception. * :dependent => :restrict_with_error implements the new behaviour - it adds an error to the owner if there are dependent records present See #4727 for the original discussion of this.
* load active_support/deprecation in active_support/railsXavier Noria2012-08-021-1/+0
|
* load active_support/core_ext/object/inclusion in active_support/railsXavier Noria2012-08-023-3/+0
|
* Deprecate :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-08-012-0/+21
|
* Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."Jon Leighton2012-08-012-2/+2
| | | | | | | | | This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370. Conflicts: activerecord/CHANGELOG.md It will be deprecated only in 4.0, and removed properly in 4.1.
* Refactor dependency check validationCarlos Antonio da Silva2012-08-014-28/+19
| | | | | | Move the logic for validation check to the same method, and cache dependent option in a variable to reuse inside the dependency configuration methods instead of relying on the options hash.
* move method for dependent option checkHrvoje Šimić2012-08-014-11/+22
|
* Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql.Jon Leighton2012-07-202-2/+2
|
* Avoid options ever being nilJon Leighton2012-07-201-4/+4
| | | | This fixes active_record_deprecated_finders.
* fix association :extend optionJon Leighton2012-07-132-6/+17
|
* move the deprecated options into active_record_deprecated_findersJon Leighton2012-07-132-5/+2
|
* stop using class_attribute where methods/inheritance will suffice.Jon Leighton2012-07-137-29/+53
|
* extract deprecated association options to active_record_deprecated_findersJon Leighton2012-07-131-43/+0
|
* Represent association scope options as AR::Relations insternally.Jon Leighton2012-07-131-0/+43
|
* Allow associations to take a lambda which builds the scopeJon Leighton2012-07-132-12/+17
|
* Improve the derivation of HABTM assocation join table namesAndrew White2012-06-221-30/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Improve the derivation of HABTM join table name to take account of nesting. It now takes the table names of the two models, sorts them lexically and then joins them, stripping any common prefix from the second table name. Some examples: Top level models (Category <=> Product) Old: categories_products New: categories_products Top level models with a global table_name_prefix (Category <=> Product) Old: site_categories_products New: site_categories_products Nested models in a module without a table_name_prefix method (Admin::Category <=> Admin::Product) Old: categories_products New: categories_products Nested models in a module with a table_name_prefix method (Admin::Category <=> Admin::Product) Old: categories_products New: admin_categories_products Nested models in a parent model (Catalog::Category <=> Catalog::Product) Old: categories_products New: catalog_categories_products Nested models in different parent models (Catalog::Category <=> Content::Page) Old: categories_pages New: catalog_categories_content_pages Also as part of this commit the validity checks for HABTM assocations have been moved to ActiveRecord::Reflection One side effect of this is to move when the exceptions are raised from the point of declaration to when the association is built. This is consistant with other association validity checks.
* Merge pull request #4835 from ↵Carlos Antonio da Silva2012-05-191-3/+3
|\ | | | | | | | | pacoguzman/refactor_define_restrict_dependency_method Refactor define_restrict_dependency_method using reflection
| * Refactor define_restrict_dependency_method using reflectionPaco Guzman2012-02-011-3/+3
| |
* | no longer need #delete_all_on_destroyJon Leighton2012-05-182-2/+2
|/
* Use human attribute name to show the dependent destroy messageRafael Mendonça França2012-02-011-1/+2
|
* fix has_one, has_many restrict error messageManoj2012-02-011-1/+2
|
* Merge pull request #4799 from arunagw/warning_fixed_for_indentationsAaron Patterson2012-01-311-1/+1
|\ | | | | warning removed: mismatched indentations
| * warning removed: mismatched indentationsArun Agrawal2012-01-311-1/+1
| |
* | Put spaces between the words at deprecation warningRafael Mendonça França2012-01-311-3/+3
|/
* suggested fixes for :dependent => :restrict deprecation.Manoj2012-01-311-1/+1
|
* Same method for has_many and has_one associationsPaco Guzman2012-01-313-30/+17
|
* Easy dependent_restrict error messagePaco Guzman2012-01-312-4/+2
|