aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/belongs_to.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* use attribute methods for finding key values rather than generating method namesAaron Patterson2013-06-111-3/+3
|
* push belongs_to counter cache method to a single methodAaron Patterson2013-06-111-17/+18
|
* push before_destroy counter cache method to a single methodAaron Patterson2013-06-111-12/+17
|
* remove evaled belongs_to counter cache methodAaron Patterson2013-06-111-8/+22
|
* adding callbacks should be privateAaron Patterson2013-06-111-4/+6
|
* 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
* Use method compilation for association methodsJon Leighton2012-08-101-32/+25
| | | | | | | | | 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-101-18/+2
|
* Unprivatise all the thingsJon Leighton2012-08-101-51/+49
| | | | | | 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-101-5/+8
|
* Clean up dependent option validation.Jon Leighton2012-08-101-1/+1
| | | | | We don't need the complexity of to_sentence, and it shouldn't be a bang method.
* load active_support/core_ext/object/inclusion in active_support/railsXavier Noria2012-08-021-1/+0
|
* Refactor dependency check validationCarlos Antonio da Silva2012-08-011-6/+4
| | | | | | 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-011-3/+3
|
* stop using class_attribute where methods/inheritance will suffice.Jon Leighton2012-07-131-2/+6
|
* Removed metaclass from the has_many dependency destroy method. Fixes #2954Dmitry Polushkin2011-12-311-2/+4
|
* avoid warningsJosh Susser2011-11-271-3/+3
| | | | | | | This change uses Module.redefine_method as defined in ActiveSupport. Making Module.define_method public would be as clean in the code, and would also emit warnings when redefining an association. That is pretty messy given current tests, so I'm leaving it for someone else to decide what approach is better.
* association methods are now generated in modulesJosh Susser2011-11-151-3/+3
| | | | | | | | | | Instead of generating association methods directly in the model class, they are generated in an anonymous module which is then included in the model class. There is one such module for each association. The only subtlety is that the generated_attributes_methods module (from ActiveModel) must be forced to be included before association methods are created so that attribute methods will not shadow association methods.
* Remove `#among?` from Active SupportPrem Sichanugrist2011-04-131-1/+1
| | | | | | After a long list of discussion about the performance problem from using varargs and the reason that we can't find a great pair for it, it would be best to remove support for it for now. It will come back if we can find a good pair for it. For now, Bon Voyage, `#among?`.
* Change Object#either? to Object#among? -- thanks to @jamesarosen for the ↵David Heinemeier Hansson2011-04-121-1/+1
| | | | suggestion!
* Using Object#in? and Object#either? in various placesPrem Sichanugrist2011-04-111-1/+3
| | | | There're a lot of places in Rails source code which make a lot of sense to switching to Object#in? or Object#either? instead of using [].include?.
* Use proper objects to do the work to build the associations (adding methods, ↵Jon Leighton2011-02-211-0/+83
callbacks etc) rather than calling a whole bunch of methods with rather long names.