aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
...
| * | | Refactor CollectionProxy#scope to avoid calling #extend.James Golick2013-04-021-4/+2
| | | |
* | | | 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.
* | | | use | to have more intent revealing codeNeeraj Singh2013-04-041-1/+1
| | | | | | | | | | | | | | | | thanks to @egilburg for suggestion
* | | | Merge pull request #10087 from neerajdotname/10016Carlos Antonio da Silva2013-04-041-0/+1
|\ \ \ \ | | | | | | | | | | has_many through obeys order on through association
| * | | | has_many through obeys order on through associationNeeraj Singh2013-04-041-0/+1
| | | | | | | | | | | | | | | | | | | | fixes #10016
* | | | | Merge pull request #10088 from neerajdotname/fixes1Rafael Mendonça França2013-04-042-5/+5
|\ \ \ \ \ | |/ / / / |/| | | | minor fixes including variable name change and expanded rdoc
| * | | | show name of the klass that has missing associationNeeraj Singh2013-04-021-1/+1
| | | | |
| * | | | not a relation. it's an arel select managerNeeraj Singh2013-04-021-4/+4
| |/ / /
* | | | 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
| | | | |
* | | | | Merge pull request #10049 from vipulnsward/optimize_around_merge_v1Rafael Mendonça França2013-04-031-1/+1
|\ \ \ \ \ | | | | | | | | | | | | optimize some code around merge
| * | | | | optimize some code around mergeVipul A M2013-04-031-1/+1
| | |_|_|/ | |/| | |
* | | | | Move alias method near to the aliased one in collection proxyCarlos Antonio da Silva2013-04-031-2/+1
| |_|/ / |/| | |
* | | | no need to invoke to_s before applying internNeeraj Singh2013-04-021-1/+1
| | | |
* | | | Updated the error message for +find+ on an inverse_of associationwangjohn2013-04-011-1/+1
| | | | | | | | | | | | | | | | | | | | so that it is consistent with the error thrown for +find+ without an inverse_of association.
* | | | Throwing a RecordNotFound exception when a record is scanned using thewangjohn2013-04-011-1/+13
|/ / / | | | | | | | | | | | | inverse_of option. I've also refactored the code for raising a RecordNotFound exception when searching for records with ids.
* | | Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-03-301-1/+2
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/adapter_test.rb guides/source/testing.md [ci skip]
| * | | explain method invertible_for [ci skip]Neeraj Singh2013-03-291-1/+2
| | | |
* | | | Do not use deprecate method [ci skip]Neeraj Singh2013-03-291-1/+1
| | | |
* | | | fix broken sentence [ci skip]Neeraj Singh2013-03-291-1/+1
| |_|/ |/| |
* | | Adding a bang to method name of raise_on_type_mismatch.wangjohn2013-03-216-8/+8
| | |
* | | Update other counter caches on destroyIan Young2013-03-202-2/+2
| | |
* | | Properly named variable inside blockAnupam Choudhury2013-03-201-2/+2
| | | | | | | | | | | | Closes #9824.
* | | Calling find() on an association with an inverse will now check to seewangjohn2013-03-191-2/+3
| | | | | | | | | | | | | | | if the association already holds that record in memory before checking the database for the specified ids.
* | | 1. Change from each to each_value since we did not use keyVipul A M2013-03-191-1/+1
| | | | | | | | | | | | 2. drop assignment of value to sum in test
* | | 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.
* | | Cache the association proxy objectJon Leighton2013-03-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | This reimplements the behaviour of Rails 3, as I couldn't see why we shouldn't cache the object, and @alindeman had a good use case for caching it: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
* | | Deprecate the `:distinct` option for `Relation#count`.Yves Senn2013-03-151-2/+3
| | | | | | | | | | | | | | | | | | | | | We moved more and more away from passing options to finder / calculation methods. The `:distinct` option in `#count` was one of the remaining places. Since we can now combine `Relation#distinct` with `Relation#count` the option is no longer necessary and can be deprecated.
* | | rename `Relation#uniq` to `Relation#distinct`. `#uniq` still works.Yves Senn2013-03-153-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | The similarity of `Relation#uniq` to `Array#uniq` is confusing. Since our Relation API is close to SQL terms I renamed `#uniq` to `#distinct`. There is no deprecation. `#uniq` and `#uniq!` are aliases and will continue to work. I also updated the documentation to promote the use of `#distinct`.
* | | hide more data in the schema cacheAaron Patterson2013-03-141-1/+1
| |/ |/|
* | dependent: :destroy should call destroy_allNeeraj Singh2013-03-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit https://github.com/rails/rails/pull/9668 shows warning when `delete_all` is invoked with `:dependent` option `:destroy`. Unfortunately invoking `Post.destroy_all` invokes `post.comments.delete_all` as part of `has_many` callbacks. This commit ensures that instead `post.comments.destroy_all` is invoked and in the process no warning is generated. See issue #9567 for details .
* | Show warning message if delete_all is firing callbacksNeeraj Singh2013-03-111-0/+9
| | | | | | | | | | | | `post.comments.delete_all` will fire callbacks if :dependent option is :destroy . It will be fixed in Rails 4.1 . In the meantime display a warning . Look at #9567 for details .
* | Deprecate #connection in favour of accessing it via the classBen Moss2013-03-091-3/+3
|/ | | | | This allows end-users to have a `connection` method on their models without clashing with ActiveRecord internals.
* deal with `#append` and `#prepend` on association collections.Yves Senn2013-03-011-0/+5
| | | | | | | | | | | Closes #7364. Collection associations behave similar to Arrays. However there is no way to prepend records. And to append one should use `<<`. Before this patch `#append` and `#prepend` did not add the record to the loaded association. `#append` now behaves like `<<` and `#prepend` is not defined.
* don't use non-ascii ' chars in documentationYves Senn2013-03-011-4/+4
|
* 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
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-02-261-1/+1
|\
| * BELONGS TO ASSOCIATION | Typo fixlibin2013-02-251-1/+1
| |
* | No need to send public methodsAkira Matsuda2013-02-262-2/+2
| |
* | don't apply invalid ordering when preloading hmt associations.Yves Senn2013-02-241-2/+2
|/ | | | | | | | | | | | | | | closes #8663. When preloading a hmt association there two possible scenarios: 1.) preload with 2 queries: first hm association, then hmt with id IN () 2.) preload with join: hmt association is loaded with a join on the hm association The bug was happening in scenario 1.) with a normal order clause on the hmt association. The ordering was also applied when loading the hm association, which resulted in the error. This patch only applies the ordering the the hm-relation if we are performing a join (2). Otherwise the order will only appear in the second query (1).
* don't cache invalid subsets when preloading hmt associations.Yves Senn2013-02-141-1/+2
| | | | closes #8423.
* Reverting 16f6f25 (Change behaviour with empty array in where clause)Guillermo Iguaran2013-02-081-1/+1
|
* Change behaviour with empty array in where clauserobertomiranda2013-02-081-1/+1
|
* Refactor to use each_key, remove extra spacesCarlos Antonio da Silva2013-01-281-1/+1
|
* Prevent Relation#merge from collapsing wheres on the RHSJon Leighton2013-01-271-4/+8
| | | | | | | | | | | | | | | | | | | | | | | This caused a bug with the new associations implementation, because now association conditions are represented as Arel nodes internally right up to when the whole thing gets turned to SQL. In Rails 3.2, association conditions get turned to raw SQL early on, which prevents Relation#merge from interfering. The current implementation was buggy when a default_scope existed on the target model, since we would basically end up doing: default_scope.merge(association_scope) If default_scope contained a where(foo: 'a') and association_scope contained a where(foo: 'b').where(foo: 'c') then the merger would see that the same column is representated on both sides of the merge and collapse the wheres to all but the last: where(foo: 'c') Now, the RHS of the merge is left alone. Fixes #8990
* Undeprecate the :extend optionJon Leighton2013-01-182-1/+3
| | | | | | | Suggested by @dhh. It doesn't affect the generated SQL, so seems reasonable to continue to allow it as an association option.
* CollectionProxy should be default scopedJon Leighton2013-01-181-0/+1
| | | | Fixes #8795
* `CollectionAssociation#empty?` respects newly builded recordsYves Senn2013-01-131-1/+1
|