aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Update belongs_to.rbEhsan Yousefi2015-11-081-2/+1
| | | There is no need to to assign reflection name to a variable, because it's called once.
* docs, `ActiveRecord::JoinDependency` is not part of the public API.Yves Senn2015-11-071-1/+1
| | | | | | | [ci skip] While `JoinDependency` and `JoinDependency::Aliases` were nodoced, the inner `Table` class made them appear in the API.
* Merge pull request #12071 from Crunch09/outer_joinsSean Griffin2015-10-301-2/+15
|\ | | | | | | added ActiveRecord::Relation#outer_joins
| * added ActiveRecord::Relation#left_outer_joinsFlorian Thomas2015-05-191-2/+15
| | | | | | | | | | | | Example: User.left_outer_joins(:posts) => SELECT "users".* FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" = "users"."id"
* | Ensure `has_and_belongs_to_many` works with `belongs_to_required_by_default`Sean Griffin2015-10-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Never pass `nil` to `order`Sean Griffin2015-10-294-16/+7
| | | | | | | | | | | | | | | | This is part of a refactoring to make it easier to allow `order` to use sanitize like just about everything else on relation. The deleted test doesn't give any reasoning as to why passing `nil` to `order` needs to be supported, and it's rather nonsensical. I can almost see allowing an empty string being passed (though I'm tempted to just disallow it...)
* | Revert "Revert "Merge pull request #22026 from ↵Yves Senn2015-10-291-0/+4
| | | | | | | | | | | | | | | | | | akihiro17/fix-preload-association"" This reverts commit 5243946017d09afff4d70d273b0fcdfd41a4b22a. This fixes an issue with the build where tests would fail on mysql and postgresql due to different ordering.
* | Revert "Merge pull request #22026 from akihiro17/fix-preload-association"Sean Griffin2015-10-291-4/+0
| | | | | | | | | | | | | | This reverts commit 6dc6a0b17cfaf7cb6aa2b1c163b6ca141b538a8e, reversing changes made to ec94f00ba3cf250eb54fc5b7a5e3ed4b90164f34. This pull request broke the build.
* | Set `scope.reordering_value` to `true` if :reordering values are specifiedakihiro172015-10-301-0/+4
| | | | | | | | | | | | We should call `scope.order!` and set `scope.reordering_value` to `true` if :reordering values are specified Fixes #21886
* | Merge pull request #18383 from ↵Rafael Mendonça França2015-10-271-1/+2
|\ \ | | | | | | | | | | | | | | | scambra/habtm-with-where-includes-16032-for-master Includes HABTM returns correct size now
| * | Includes HABTM returns correct size now. It's caused by the join dependencySergio Cambra2015-01-071-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | only instantiates one HABTM object because the join table hasn't a primary key. Updated commit from @bigxiang commit dbaa837 Fixes #16032. Examples: before: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 1 after: Project.first.salaried_developers.size # => 3 Project.includes(:salaried_developers).first.salaried_developers.size # => 3
* | | [ci skip] Add doc for preloader_forschneems2015-10-261-0/+4
| | |
* | | [ci skip] Clarify doc for preloaders_for_oneschneems2015-10-261-0/+5
| | |
* | | [ci skip] Add doc to preloaders_onschneems2015-10-261-0/+1
| | |
* | | Merge pull request #19686 from tsun1215/index_errorsSean Griffin2015-10-261-1/+1
|\ \ \ | | | | | | | | | | | | | | | | | | | | Errors can be indexed with nested attributes Close #8638
| * | | Errors can be indexed with nested attributesMichael Probber2015-04-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `has_many` can now take `index_errors: true` as an option. When this is enabled, errors for nested models will be returned alongside an index, as opposed to just the nested model name. This option can also be enabled (or disabled) globally through `ActiveRecord::Base.index_nested_attribute_errors` E.X. ```ruby class Guitar < ActiveRecord::Base has_many :tuning_pegs accepts_nested_attributes_for :tuning_pegs end class TuningPeg < ActiveRecord::Base belongs_to :guitar validates_numericality_of :pitch end ``` - Old style - `guitar.errors["tuning_pegs.pitch"] = ["is not a number"]` - New style (if defined globally, or set in has_many_relationship) - `guitar.errors["tuning_pegs[1].pitch"] = ["is not a number"]` [Michael Probber, Terence Sun]
* | | | [ci skip] Fix method documentation locationschneems2015-10-261-3/+2
| | | |
* | | | Merge pull request #21918 from bogdan/refactor-preloaderSean Griffin2015-10-221-42/+30
|\ \ \ \ | | | | | | | | | | Refactored association preloader for performance
| * | | | Refactored association preloader for performanceBogdan Gusiev2015-10-221-42/+30
| | | | | | | | | | | | | | | | | | | | | | | | | * less arrays created * less complexity with only one level of nesting in loop
* | | | | Fix merge conflicts for #19938Sean Griffin2015-10-201-6/+5
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | This is a separate commit, as it is not just a changelog conflict. Want to point out the changes in the code
| * | | | | Fix for activerecord join dependency instantiate bugMehmet Emin İNAÇ2015-05-041-6/+5
| | |_|_|/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | use only object_id instead parent class and parent id test cases assert_equal use table name in references fix minor problems
* | | | | Changed the order of Association constraints from where->order->unscope to ↵kal2015-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | unscope->where->order
* | | | | Delete needless `require 'active_support/deprecation'`yui-knk2015-10-202-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | When `require 'active_support/rails'`, 'active_support/deprecation' is automatically loaded.
* | | | | applies new doc guidelines to Active Record.Yves Senn2015-10-141-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* | | | | fix broken RDoc markup. Use `<tt>` instead of `+`. [ci skip]Yves Senn2015-10-141-3/+3
| | | | |
* | | | | docs, add missing `:nodoc: for `Associations::Builder`. [ci skip]Yves Senn2015-10-137-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This class is only used internally. We should keep it out of public documentation. This patch adds nodoc for `ActiveRecord::Associations::Builder` and everything nested within.
* | | | | nodoc `ActiveRecord::ForeignAssociation`. [ci skip]Yves Senn2015-10-131-1/+1
| | | | |
* | | | | Merge pull request #11410 from bogdan/increment-concurencyJeremy Daer2015-10-102-35/+21
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | Make AR#increment! and #decrement! concurrency-safe
| * | | | | Make #increment! and #decrement! methods concurency safeBogdan Gusiev2015-10-052-35/+21
| | | | | |
* | | | | | Merge pull request #21033 from dgynn/preloader_build_scope_tuningArthur Nogueira Neves2015-10-041-1/+3
|\ \ \ \ \ \ | |_|_|/ / / |/| | | | | Skip _select! call unless needed for preloader
| * | | | | skip _select! call unless :select values are specifiedDave Gynn2015-07-261-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the default scope will select all fields. removing this improves performance and reduces String creation.
* | | | | | no more class methods for JoinDependency [ci skip]Gaurav Sharma2015-09-291-2/+1
| | | | | | | | | | | | | | | | | | `ActiveRecord::Associations::JoinDependency` now it’s own class` and `ActiveRecord::Associations::ThroughAssociationScope` doesn’t exists
* | | | | | Fix `ActiveRecord::RecordNotFound` error message with custom primary key [ci ↵amitkumarsuroliya2015-09-261-7/+7
| |/ / / / |/| | | | | | | | | | | | | | skip]
* | | | | Clean up the implementation of AR::DirtySean Griffin2015-09-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This moves a bit more of the logic required for dirty checking into the attribute objects. I had hoped to remove the `with_value_from_database` stuff, but unfortunately just calling `dup` on the attribute objects isn't enough, since the values might contain deeply nested data structures. I think this can be cleaned up further. This makes most dirty checking become lazy, and reduces the number of object allocations and amount of CPU time when assigning a value. This opens the door (but doesn't quite finish) to improving the performance of writes to a place comparable to 4.1
* | | | | Merge pull request #21550 from didacte/unscope-associationsSean Griffin2015-09-241-1/+1
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | ActiveRecord: use association's `unscope` when preloading
| * | | | | Include association's `unscope` when preloadingJimmy Bourassa2015-09-091-1/+1
| | | | | |
* | | | | | Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-09-181-1/+1
|\ \ \ \ \ \
| * | | | | | [ci skip] Fix module name of documentyui-knk2015-09-171-1/+1
| |/ / / / /
* | | | | | `restrict_with_error` message will now respect owner’s human name in any ↵Ronak Jangir2015-09-122-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | locale [kuboon & Ronak Jangir]
* | | | | | Merge pull request #21486 from bogdan/refactor-has-many-counter-cacheEileen M. Uchitelle2015-09-092-61/+10
|\ \ \ \ \ \ | | | | | | | | | | | | | | HasManyAssociation: moved half of counter cache code to reflection
| * | | | | | HasManyAssociation: moved half of counter cache code to reflectionBogdan Gusiev2015-09-032-61/+10
| |/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Current implementation has a lot of utility methods that accept reflection call a lot of methods on it and exit. E.g. has_counter_cache?(reflection) It causes confusion and inability to cache result of the method even through it always returns the same result for the same reflection object. It can be done easier without access to the association context by moving code into reflection itself. e.g. reflection.has_counter_cache? Reflection is less complex object than association so moving code there automatically makes it simplier to understand.
* / / / / / Added nodoc for `arel` method which returns object of private api. [ci skip]Ronak Jangir2015-09-091-1/+1
|/ / / / /
* | | | | Only nullify persisted has_one target associationsAgis-2015-08-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since after 87d1aba3c `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.
* | | | | Added docs for CollectionProxy#take [ci skip]Ronak Jangir2015-08-231-0/+25
| | | | |
* | | | | Correct error message in Standard American english and add a test case for ↵prakash2015-08-181-1/+1
| | | | | | | | | | | | | | | | | | | | the same.
* | | | | Merge pull request #19683 from tristang/require-option-for-counter-cacheRafael Mendonça França2015-08-131-1/+8
|\ \ \ \ \ | | | | | | | | | | | | | | | | | | Require explicit counter_cache option for has_many
| * | | | | Require explicit counter_cache option for has_manyTristan Gamilis2015-04-071-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | | | | Skip statement cache on through association readerRafael Mendonça França2015-08-123-12/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the through class has default scopes we should skip the statement cache. Closes #20745.
* | | | | | use correct DB connection for generated HABTM tableMatt Hanlon2015-08-071-3/+7
| | | | | |
* | | | | | Use memoization for collection associations ids readerMehmet Emin İNAÇ2015-08-031-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #21082 remove extra space