aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/through_association.rb
Commit message (Collapse)AuthorAgeFilesLines
* Initialization block is a part of `build_record`Ryuta Kamizono2018-06-041-1/+1
| | | | Should be done before `before_add` callbacks.
* Fix building has_one through recordRyuta Kamizono2018-01-231-0/+4
| | | | Fixes #31762.
* Fix `stale_state` for nested `has_many :through` associationsRyuta Kamizono2018-01-101-2/+13
| | | | Need reloading when through record has replaced.
* Merge pull request #16314 from ↵Ryuta Kamizono2018-01-101-1/+1
|\ | | | | | | | | | | zoltankiss/allow-nested-has-many-associations-on-unpersisted-parent-instances fix nested `has many :through` associations on unpersisted parent instances
| * Fix nested `has many :through` associations on unpersisted instancesZoltan Kiss2015-03-261-1/+1
| | | | | | | | Fixes: #16313
* | Fix deleting through records when using has_many through with `source_type`Ryuta Kamizono2018-01-081-8/+6
| | | | | | | | | | | | | | | | Currently deleting through records doesn't respect `source_type`. It should not be ignored in that case. Related #23209. Fixes #24116.
* | Fix broken doc for Active Record [ci skip]Yoshiyuki Hirano2017-08-251-1/+1
| |
* | Through scope should not be affected by scopingRyuta Kamizono2017-08-151-1/+1
| | | | | | | | | | | | Follow up of #29834. Fixes #30266.
* | Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
| |
* | Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* | Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| |
* | No need `:doc:` for `:nodoc:` classes [ci skip]Ryuta Kamizono2016-12-251-1/+1
| | | | | | | | | | | | Follow up to 5b14129d8d4ad302b4e11df6bd5c7891b75f393c. http://edgeapi.rubyonrails.org/classes/ActiveRecord/Attribute.html
* | Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-4/+2
| |
* | applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
| |
* | modernizes hash syntax in activerecordXavier Noria2016-08-061-1/+1
| |
* | Fix misleading errors for has_one through relationsMehmet Emin İNAÇ2015-07-221-2/+10
| |
* | Correct through associations using scopesSean Griffin2015-06-301-6/+0
|/ | | | | | | | | | | | | | | | | | | | | | The changes introduced to through associations in c80487eb were quite interesting. Changing `relation.merge!(scope)` to `relation = relation.merge(scope)` should in theory never cause any changes in behavior. The subtle breakage led to a surprising conclusion. The old code wasn't doing anything! Since `merge!` calls `instance_exec` when given a proc, and most scopes will look something like `has_many :foos, -> { where(foo: :bar) }`, if we're not capturing the return value, it's a no-op. However, removing the `merge` causes `unscope` to break. While we're merging in the rest of the chain elsewhere, we were never merging in `unscope` values, causing a breakage on associations where a default scope was being unscoped in an association scope (yuk!). This is subtly related to #20722, since it appears we were previously relying on this mutability. Fixes #20721. Fixes #20727.
* Doc fix [ci skip]Sushruth Sivaramakrishnan2015-03-071-1/+1
|
* Don't rely on relation mutability when building through associationsSean Griffin2015-01-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | Specifically, the issue is relying on `where_unscoping` mutating the where values. It does not, however, mutate the bind values, which could cause an error under certain circumstances. This was not exposed by the tests, since the only place which would have been affected is unscoping a boolean, which doesn't go through prepared statements. I had a hard time getting better test coverage to demonstrate the issue. This in turn, caused `merge` to go through proper logic, and try to clear out the binds associated with the unscoped relation, which then exposed a source of `nil` for the columns, as binds weren't expanding `{ "posts.id" => 1 }` to `{ "posts" => { "id" => 1 } }`. This has been fixed. The bulk of `create_binds` needed to be moved to a separate method, since the dot notation should not be expanded recursively. I'm pretty sure this removes a subtle quirk that a ton of code in `Relation::Merger` is working around, and I suspect that code can be greatly simplified. However, unraveling that rats nest is no small task.
* Merge pull request #15309 from iantropov/issue_12698_build_throughRafael Mendonça França2015-01-021-0/+11
|\ | | | | | | | | | | | | | | Add setting of FK for throgh associations while building Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Add setting of FK for throgh associations while buildingIvan Antropov2014-05-251-0/+11
| |
* | Only merge scopes with zero arity in has_many throughAgis-2014-08-201-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with dynamic conditions. Fixes #16128 This bug was introduced in https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d so it's present from 4.1.2-rc1 and after. https://github.com/rails/rails/commit/c35e438620f2d56562251571377995359546393d merges any relation scopes passed as proc objects to the relation, but does *not* take into account the arity of the lambda. To reproduce: https://gist.github.com/Agis-/5f1f0d664d2cd08dfb9b
* | Don't delegate Reflection#chain to ThroughAssociationeileencodes2014-08-041-2/+2
| | | | | | | | | | | | We shouldn't be delegating chain to ThroughAssociation since the only place that needs to call it is `target_scope`. Instead we can call `reflecion.chain`.
* | Use available method rather than macro name checkingCarlos Antonio da Silva2014-07-311-1/+1
| |
* | Through associations should set both parent ids on join modelsSean Griffin2014-06-131-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | member = Member.new(club: Club.new) member.save! Before: member.current_membership.club_id # => nil After: member.current_membership.club_id # => club's id
* | reuse available belongs_to? methodeileencodes2014-06-031-3/+2
|/ | | | | | | | | | Reflection has a `belongs_to?` method. Instead of checking for `macro == :belongs_to` throughout the source reuse existing method. I also bumped `foreign_key_present?` method onto on line because the `belongs_to?` makes it shorter than other longer lines in the same class.
* Merge pull request #14573 from habermann24/has_many_through_fixRafael Mendonça França2014-04-221-2/+4
|\ | | | | | | | | | | | | | | Properly handle scoping with has_many :through. Fixes #14537. Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/associations/has_many_through_associations_test.rb
| * Minor improvement: Use the merge method on the relation instead of ↵Jan Habermann2014-04-031-1/+1
| | | | | | | | instance_eval directly.
| * Simplify the code in target_scopeJan Habermann2014-04-031-5/+2
| |
| * Properly handle scoping with has_many :through. Fixes #14537.Jan Habermann2014-04-031-2/+7
|/
* use drop and avoid a range objectAaron Patterson2013-08-011-1/+1
|
* Simplify/fix implementation of default scopesJon Leighton2013-06-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation was necessary in order to support stuff like: class Post < ActiveRecord::Base default_scope where(published: true) scope :ordered, order("created_at") end If we didn't evaluate the default scope at the last possible moment before sending the SQL to the database, it would become impossible to do: Post.unscoped.ordered This is because the default scope would already be bound up in the "ordered" scope, and therefore wouldn't be removed by the "Post.unscoped" part. In 4.0, we have deprecated all "eager" forms of scopes. So now you must write: class Post < ActiveRecord::Base default_scope { where(published: true) } scope :ordered, -> { order("created_at") } end This prevents the default scope getting bound up inside the "ordered" scope, which means we can now have a simpler/better/more natural implementation of default scoping. A knock on effect is that some things that didn't work properly now do. For example it was previously impossible to use #except to remove a part of the default scope, since the default scope was evaluated after the call to #except.
* optimize some code around mergeVipul A M2013-04-031-1/+1
|
* Migration of docs to 1.9 hash syntaxAvnerCohen2012-10-231-1/+1
|
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-1/+1
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* @stale_state should be nil when a model isn't saved.kennyj2012-04-131-1/+1
|
* Not need to pass join attributes to association buildRafael Mendonça França2012-03-071-3/+7
|
* Fix #3247.Jon Leighton2011-11-031-1/+1
| | | | | Fixes creating records in a through association with a polymorphic source type.
* Don't include any of includes, preload, joins, eager_load in the through ↵Jon Leighton2011-09-071-1/+1
| | | | association scope.
* Nested through associations: preloads from the default scope of a through ↵Jon Leighton2011-09-061-1/+1
| | | | model should not be included in the association scope. (We're already excluding includes.) Fixes #2834.
* Ignore :includes on through associationsAndrew White2011-05-241-1/+1
|
* Don't use select() values from the join model of a through association. ↵Jon Leighton2011-05-111-3/+4
| | | | Fixes #508.
* Don't use mass-assignment protection when applying the ↵Jon Leighton2011-05-101-1/+3
| | | | scoped.scope_for_create. Fixes #481.
* Resolve some TODO comments which I decided did not need anything doneJon Leighton2011-03-121-7/+4
|
* Rename Reflection#through_reflection_chain and #through_options to ↵Jon Leighton2011-03-101-3/+2
| | | | Reflection#chain and Reflection#options as they now no longer relate solely to through associations.
* Move the code which builds a scope for through associations into a generic ↵Jon Leighton2011-03-101-128/+0
| | | | AssociationScope class which is capable of building a scope for any association.
* Fix ↵Jon Leighton2011-03-071-1/+1
| | | | test_has_many_association_through_a_has_many_association_with_nonstandard_primary_keys
* Refactor ThroughAssociation#join_to to be much smaller, and independent of ↵Jon Leighton2011-03-061-84/+28
| | | | construct_owner_conditions.
* Refactor ThroughAssociation#tables to just be a flat array of tables in the ↵Jon Leighton2011-03-061-75/+70
| | | | order that they should be joined together.
* Push source_type and polymorphic conditions out of ThroughAssociation and ↵Jon Leighton2011-03-051-17/+0
| | | | JoinDependency::JoinAssociation and into the reflection instead.