aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #18109 from k0kubun/unscoped-joinsSean Griffin2016-02-111-6/+12
|\ | | | | | | | | | | Allow `joins` to be unscoped Fixes #13775
| * Allow `joins` to be unscopedTakashi Kokubun2016-01-311-6/+12
| |
* | rename to 'second_to_last' and 'third_to_last'Brian Christian2016-02-102-8/+8
| |
* | allow Array.penultimate and Array.antepenultiate access methodsBrian Christian2016-02-092-0/+18
| |
* | Merge pull request #23457 from matthewd/arel-attributeMatthew Draper2016-02-042-2/+2
|\ \ | | | | | | Defer Arel attribute lookup to the model class
| * | Defer Arel attribute lookup to the model classMatthew Draper2016-02-042-2/+2
| |/ | | | | | | | | This still isn't as separated as I'd like, but it at least moves most of the burden of alias mapping in one place.
* | Merge pull request #20997 from himesh-r/issue-20995Arthur Neves2016-02-021-1/+4
|\ \ | |/ |/| | | | | Changed id-writer to save join table records based on association primary key #20995.
| * Changed id-writer to save join table records based on association primary ↵Himesh2016-02-021-1/+4
| | | | | | | | | | | | key #20995 Changed id-writer to save join table records based on association primary key
* | Add missing source_type if provided on hmt which belongs to an sti recordVipul A M2016-01-241-0/+5
| | | | | | | | Fixes #23209
* | Define `:foreign_type` as a valid option in `SingularAssociation`yui-knk2016-01-193-3/+3
| | | | | | | | | | `:foreign_type` is a valid option for `belongs_to` and `has_one` so remove this to `SingularAssociation`.
* | `substitute_at` is no longer usedRyuta Kamizono2016-01-141-2/+1
| | | | | | | | Arel handles substitution for bind parameters by now.
* | Revert "Merge pull request #22486 from ↵Yves Senn2015-12-211-5/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | methyl/fix-includes-for-groupped-association" This reverts commit 537ac7d6ade61e95f2b70685ff2236b7de965bab, reversing changes made to 9c9c54abe08d86967efd3dcac1d65158a0ff74ea. Reason: The way we preload associations will change the meaning of GROUP BY operations. This is illustrated in the SQL generated by the added test (failing on PG): Association Load: D, [2015-12-21T12:26:07.169920 #26969] DEBUG -- : Post Load (0.7ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" = $1 GROUP BY posts.id ORDER BY SUM(comments.tags_count) [["author_id", 1]] Preload: D, [2015-12-21T12:26:07.128305 #26969] DEBUG -- : Post Load (1.3ms) SELECT "posts".* FROM "posts" LEFT JOIN comments ON comments.post_id = posts.id WHERE "posts"."author_id" IN (1, 2, 3) GROUP BY posts.id ORDER BY SUM(comments.tags_count)
* | Merge pull request #22486 from methyl/fix-includes-for-groupped-associationYves Senn2015-12-211-1/+5
|\ \ | | | | | | | | | | | | | | | | | | Pass group values when including association Conflicts: activerecord/CHANGELOG.md
| * | Pass SQL group by values when including scoped associationLucjan Suski2015-12-151-1/+5
| | | | | | | | | | | | | | | Fixes problem when added `group()` in association scope was lost in eager loaded association.
* | | Merge pull request #19423 from ↵Aaron Patterson2015-12-181-2/+7
|\ \ \ | |/ / |/| | | | | | | | yuroyoro/fix_performance_regression_of_preloading_has_many_through_relation Fix #12537 performance regression when preloading has_many_through association
| * | Read already loaded association records from association.targetTomohito Ozaki2015-04-171-2/+7
| | | | | | | | | | | | | | | For performance, Avoid instantiate CollectionProxy. Fixes #12537
* | | Make sure we touch all the parents when touch_later.Arthur Neves2015-12-061-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was that when saving an object, we would call touch_later on the parent which wont be saved immediteally, and it wont call any callbacks. That was working one level up because we were calling touch, during the touch_later commit phase. However that still didnt solve the problem when you have a 3+ levels of parents to be touched, as calling touch would affect the parent, but it would be too late to run callbacks on its grand-parent. The solution for this, is instead, call touch_later upwards when the first touch_later is called. So we make sure all the timestamps are updated without relying on callbacks. This also removed the hard dependency BelongsTo builder had with the TouchLater module. So we can still have the old behaviour if TouchLater module is not included. [fixes 5f5e6d924973003c105feb711cefdb726f312768] [related #19324]
* | | Bugfix collection association #create method …Bogdan Gusiev2015-11-231-4/+8
| | | | | | | | | | | | | | | When same association is loaded in the model creation callback The new object is inserted into association twice
* | | Except keys of `build_record`'s argument from `create_scope` in ↵yui-knk2015-11-161-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | initialize_attributes If argument of `build_record` has key and value which is same as default value of database, we should also except the key from `create_scope` in `initialize_attributes`. Because at first `build_record` initialize record object with argument of `build_record`, then assign attributes derived from Association's scope. In this case `record.changed` does not include the key, which value is same as default value of database, so we should add the key to except list. Fix #21893.
* | | 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.