aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations
Commit message (Collapse)AuthorAgeFilesLines
...
| | * Enforce frozen string in RubocopKir Shatrov2017-07-0135-0/+35
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-021-2/+1
| |\ \ | | | | | | | | | | | | Make ActiveSupport frozen-string-literal friendly.
| | * | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-2/+1
| | | |
| * | | Merge pull request #29631 from kamipo/should_be_clear_association_idsMatthew Draper2017-07-011-2/+11
| |\ \ \ | | | | | | | | | | Should be clear `@association_ids` when joined newly associated record
| | * | | Should be clear `@association_ids` when joined newly associated recordRyuta Kamizono2017-06-301-2/+11
| | | |/ | | |/| | | | | | | | | Fixes #29627.
* | / | [Active Record] require => require_relativeAkira Matsuda2017-07-013-3/+3
|/ / /
* / / Delete stale comment for `AR::Associations::Builder::CollectionAssociation`fatkodima2017-07-011-2/+0
|/ /
* | Merge pull request #29616 from kamipo/remove_unused_aliased_table_nameRafael França2017-06-291-8/+0
|\ \ | | | | | | Remove unused `aliased_table_name` in `Association`
| * | Remove unused `aliased_table_name` in `Association`Ryuta Kamizono2017-06-291-8/+0
| | | | | | | | | | | | | | | | | | | | | `aliased_table_name` in `Association` was added at a3502c4. `aliased_table_name` in `JoinDependency` (added at 55854c4) is used, but it looks like that added one in `Association` is never used from the beginning.
* | | Merge pull request #29129 from kamipo/prevent_extra_through_scopeRafael França2017-06-281-2/+4
|\ \ \ | |/ / |/| | Prevent extra `through_scope`
| * | Prevent extra `through_scope`Ryuta Kamizono2017-05-181-2/+4
| | | | | | | | | | | | We can reuse `through_scope` for `reset_association`.
* | | Merge pull request #29610 from ↵Rafael França2017-06-284-7/+7
|\ \ \ | | | | | | | | | | | | | | | | kamipo/dont_passing_klass_connection_to_association_scope Don't passing `klass.connection` to `AssociationScope`
| * | | Don't passing `klass.connection` to `AssociationScope`Ryuta Kamizono2017-06-294-7/+7
| | | | | | | | | | | | | | | | | | | | Passing `klass.connection` is redundant because `AssociationScope` is passed an association itself and an association has `klass`.
* | | | Merge pull request #29604 from ↵Rafael França2017-06-281-4/+1
|\ \ \ \ | |/ / / |/| | | | | | | | | | | kamipo/fix_ids_reader_to_respect_case_sensitive_pk Fix `ids_reader` to respect case sensitive primary key
| * | | Fix `ids_reader` to respect case sensitive primary keyRyuta Kamizono2017-06-281-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```ruby car = Car.create!(name: "Tofaş") # Before car.bulb_ids # => SELECT "bulbs".ID FROM "bulbs" WHERE "bulbs"."name" = $1 AND "bulbs"."car_id" = $2 [["name", "defaulty"], ["car_id", 3]] # After car.bulb_ids # => SELECT "bulbs"."ID" FROM "bulbs" WHERE "bulbs"."name" = $1 AND "bulbs"."car_id" = $2 [["name", "defaulty"], ["car_id", 3]] ```
* | | | Merge pull request #29593 from kratob/masterEileen M. Uchitelle2017-06-281-0/+5
|\ \ \ \ | |/ / / |/| | | ActiveRecord: do not create "has many through" records that have been removed
| * | | ActiveRecord: do not create "has many through" records that have been removedTobias Kraze2017-06-281-0/+5
| | | | | | | | | | | | | | | | | | | | If a record was built on a HasManyThroughAssociation, then removed, and then the record was saved, the removed record would be created anyways.
* | | | Merge pull request #29589 from kamipo/refactor_join_scopeRafael França2017-06-271-47/+3
|\ \ \ \ | | | | | | | | | | Refactor join dependency to move building constraints to `join_scope` in `Reflection`
| * | | | Move building constraint to `join_scope` in `Reflection`Ryuta Kamizono2017-06-271-39/+3
| | | | |
| * | | | Move constructing polymorphic type to `join_scope` in `Reflection`Ryuta Kamizono2017-06-271-10/+2
| |/ / /
* / / / Skip instantiating `NullPreloader` if `assoc.klass` is nilRyuta Kamizono2017-06-271-11/+3
|/ / / | | | | | | | | | | | | Simply we can skip instantiating `NullPreloader` if `assoc.klass` is nil.
* | | Merge pull request #29557 from kamipo/extract_build_scope_and_predicate_builderRafael França2017-06-262-13/+4
|\ \ \ | | | | | | | | Extract `build_scope` and `predicate_builder` in `Reflection`
| * | | Move constructing join scope to `Reflection`Ryuta Kamizono2017-06-261-9/+1
| | | |
| * | | Extract `build_scope` and `predicate_builder` in `Reflection`Ryuta Kamizono2017-06-242-5/+4
| | | |
* | | | Merge pull request #29568 from kamipo/ensure_using_correct_alias_trackerRafael França2017-06-263-14/+18
|\ \ \ \ | | | | | | | | | | Ensure that using correct alias tracker
| * | | | The AliasTracker#aliased_table_for needs the type caster for the joined ↵Ray Zane2017-06-253-14/+18
| |/ / / | | | | | | | | | | | | association, not the join root
* | | | Merge pull request #29511 from jhawthorn/clear_offsets_cache_on_collection_proxyRafael França2017-06-261-0/+1
|\ \ \ \ | |/ / / |/| | | Rails 5.1.2.rc1 regression - Clear offset cache on CollectionProxy reset/reload
| * | | Move clearing of @offsets cache to reset_scopeJohn Hawthorn2017-06-211-2/+1
| | | |
| * | | Clear offset cache on CollectionProxy reset/reloadJohn Hawthorn2017-06-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `@offsets` cache is used by FinderMethods to cache records found by find_nth. This cache is cleared in AR::Relation#reset, but not in CollectionProxy#reset or CollectionProxy#reload. Because of this, since #29098, calling #first/#find_nth/etc after calling #reload or #reset on an association could return a stale record. This is an issue both when the full association target is loaded and when the item is loaded in #find_nth. This commit solves the problem by clearing the `@offsets` cache in CollectionProxy#reset and CollectionProxy#reload.
* | | | Keep INNER JOIN when merging relationsMaxime Lapointe2017-06-201-3/+3
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Doing `Author.joins(:posts).merge(Post.joins(:comments))` does this `SELECT ... INNER JOIN posts ON... LEFT OUTER JOIN comments ON...` instead of doing `SELECT ... INNER JOIN posts ON... INNER JOIN comments ON...`. This behavior is unexpected and makes little sense as, basically, doing `Post.joins(:comments)` means I want posts that have comments. Turning it to a LEFT JOIN means I want posts and join the comments data, if any. We can see this problem directly in the existing tests. The test_relation_merging_with_merged_joins_as_symbols only does joins from posts to comments to ratings while the ratings fixture isn't loaded, but the count is non-zero.
* | / Prevent extra `scope` construction in `find_target`Ryuta Kamizono2017-06-183-3/+5
| |/ |/| | | | | Because constructing `scope` is a little expensive.
* | Raise on create for singular association when parent is unpersistedAlex Kitchens2017-06-081-0/+4
| | | | | | | | | | | | A collection association will raise on `#create_association` when the parent is unpersisted. A singular association should do the same. This addresses issue #29219.
* | Don't expose methods and attrs for internal usageRyuta Kamizono2017-05-304-8/+10
| |
* | Merge pull request #29098 from kamipo/fix_association_with_extension_issuesMatthew Draper2017-05-304-26/+22
|\ \ | | | | | | | | | Fix association with extension issues
| * | Extract `default_extensions` to avoid `klass.all`Ryuta Kamizono2017-05-301-1/+1
| | | | | | | | | | | | | | | As @matthewd's suggestion, if `klass` has no default scope, it will more faster.
| * | Cache the association proxy objectRyuta Kamizono2017-05-282-4/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some third party modules expects that association returns same proxy object each time (e.g. for stubbing collection methods: https://github.com/rspec/rspec-rails/issues/1817). So I decided that cache the proxy object and reset scope in the proxy object each time. Related context: https://github.com/rails/rails/commit/c86a32d7451c5d901620ac58630460915292f88b#commitcomment-2784312
| * | Fix association with extension issuesRyuta Kamizono2017-05-283-22/+14
| | | | | | | | | | | | | | | | | | | | | | | | This fixes the following issues. * `association_scope` doesn't include `default_scope`. Should use `scope` instead. * We can't use `method_missing` for customizing existing method. * We can't use `relation_delegate_class` for sharing extensions. Should extend per association.
* | | Remove unused `Association#interpolate`Ryuta Kamizono2017-05-281-8/+0
|/ / | | | | | | Using `Association#interpolate` was removed since #11251.
* | Merge pull request #29174 from kamipo/remove_unused_join_part_nameMatthew Draper2017-05-241-4/+0
|\ \ | | | | | | Remove unused `JoinPart#name`
| * | Remove unused `JoinPart#name`Ryuta Kamizono2017-05-221-4/+0
| |/
* / Refactor making join constraintsRyuta Kamizono2017-05-231-23/+6
|/ | | | | The only difference between `make_inner_joins` and `make_left_outer_joins` is the `join_type`.
* Remove useless `target_records_from_association`Ryuta Kamizono2017-05-041-11/+3
| | | | Since through association is always loaded by `preloader.preload`.
* Evaluate belongs_to :default option against the owner, not the associationGeorge Claghorn2017-04-271-1/+1
|
* Mixin `CollectionProxy::DelegateExtending` after `ClassSpecificRelation`Ryuta Kamizono2017-04-221-10/+18
| | | | | | | | | | `ClassSpecificRelation` has `method_missing` and the `method_missing` is called first. if an associated class has the missing method in a relation, never reach to the `method_missing` in the `CollectionProxy`. I extracted `DelegateExtending` and included it to the delegate class that including `ClassSpecificRelation` to fix the issue. Fixes https://github.com/rails/rails/pull/28246#issuecomment-296033784.
* Prevent double firing the before save callback of new object when the parent ↵Ryuta Kamizono2017-04-213-46/+34
| | | | | | | | | | | | | | | | | | association saved in the callback Related #18155, #26661, 268a5bb, #27434, #27442, and #28599. Originally #18155 was introduced for preventing double insertion caused by the after save callback. But it was caused the before save issue (#26661). 268a5bb fixed #26661, but it was caused the performance regression (#27434). #27442 added new record to `target` before calling callbacks for fixing #27434. But it was caused double firing before save callback (#28599). We cannot add new object to `target` before saving the object. This is improving #18155 to only track callbacks after `save`. Fixes #28599.
* Remove `CollectionProxy#uniq`Ryuta Kamizono2017-03-231-4/+0
| | | | | Since #28473 `uniq` is delegated to `records`, so `CollectionProxy#uniq` is unnecessary.
* Fix extension method with dirty target in has_many associationsRyuta Kamizono2017-03-201-2/+3
| | | | | | | Extension methods should not delegate to `scope` to respect dirty target on `CollectionProxy`. Fixes #28419.
* Evaluate the default block only when necessaryRyuta Kamizono2017-03-202-3/+3
| | | | Follow up of #28453.
* Add :default option to belongs_to (#28453)George Claghorn2017-03-172-1/+12
| | | | | | | | | | | Use it to specify that an association should be initialized with a particular record before validation. For example: # Before belongs_to :account before_validation -> { self.account ||= Current.account } # After belongs_to :account, default: -> { Current.account }
* Fix select with block doesn't return newly built records in has_many associationRyuta Kamizono2017-03-091-2/+2
| | | | | | | | The `select` in `QueryMethods` is also an enumerable method. Enumerable methods with block should delegate to `records` on `CollectionProxy`, not `scope`. Fixes #28348.