aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/through_association.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Add a test for STI on the through where the through is nested, and change ↵Jon Leighton2011-03-051-13/+22
| | | | the code which support this
* Merge branch 'master' into nested_has_many_throughJon Leighton2011-03-041-49/+172
| | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: activerecord/CHANGELOG activerecord/lib/active_record/association_preload.rb activerecord/lib/active_record/associations.rb activerecord/lib/active_record/associations/class_methods/join_dependency.rb activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb activerecord/lib/active_record/associations/has_many_association.rb activerecord/lib/active_record/associations/has_many_through_association.rb activerecord/lib/active_record/associations/has_one_association.rb activerecord/lib/active_record/associations/has_one_through_association.rb activerecord/lib/active_record/associations/through_association_scope.rb activerecord/lib/active_record/reflection.rb activerecord/test/cases/associations/has_many_through_associations_test.rb activerecord/test/cases/associations/has_one_through_associations_test.rb activerecord/test/cases/reflection_test.rb activerecord/test/cases/relations_test.rb activerecord/test/fixtures/memberships.yml activerecord/test/models/categorization.rb activerecord/test/models/category.rb activerecord/test/models/member.rb activerecord/test/models/reference.rb activerecord/test/models/tagging.rb
* Delegate through_reflection and source_reflection to reflectionJon Leighton2011-02-211-23/+23
|
* Delegate Association#options to the reflection, and replace ↵Jon Leighton2011-02-211-9/+11
| | | | 'reflection.options' with 'options'. Also add through_options and source_options methods for through associations.
* Associations - where possible, call attributes methods rather than directly ↵Jon Leighton2011-02-211-34/+34
| | | | accessing the instance variables
* Add :nodoc: to ThroughAssociation and HasOneAssociationJon Leighton2011-02-181-1/+1
|
* Add interpolation of association conditions back in, in the form of proc { ↵Jon Leighton2011-02-141-2/+2
| | | | ... } rather than instance_eval-ing strings
* Remove Relation#& alias for Relation#mergeErnie Miller2011-02-121-1/+1
|
* Support the :dependent option on has_many :through associations. For ↵Jon Leighton2011-02-071-7/+26
| | | | historical and practical reasons, :delete_all is the default deletion strategy employed by association.delete(*records), despite the fact that the default strategy is :nullify for regular has_many. Also, this only works at all if the source reflection is a belongs_to. For other situations, you should directly modify the through association.
* Make use of helpers in AssociationReflectionJon Leighton2011-01-301-4/+4
|
* Has many through - It is not necessary to manually merge in the conditions ↵Jon Leighton2011-01-301-4/+0
| | | | hash for the through record, because the creation is done directly on the through association, which will already handle setting the conditions.
* Don't pass around conditions as strings in ThroughAssociationJon Leighton2011-01-301-30/+25
|
* Indent methods under private/protected sectionsJon Leighton2011-01-301-101/+101
|
* Let's be less blasé about method visibility on association proxiesJon Leighton2011-01-301-7/+9
|
* Construct an actual ActiveRecord::Relation object for the association scope, ↵Jon Leighton2011-01-071-13/+8
| | | | rather than a hash which is passed to apply_finder_options. This allows more flexibility in how the scope is created, for example because scope.where(a, b) and scope.where(a).where(b) mean different things.
* Create the association scope directly rather than going through with_scopeJon Leighton2011-01-031-9/+6
|
* Let AssociationCollection#find use #scoped to do its finding. Note that I am ↵Jon Leighton2011-01-031-14/+5
| | | | removing test_polymorphic_has_many_going_through_join_model_with_disabled_include, since this specifies different behaviour for an association than for a regular scope. It seems reasonable to expect scopes and association proxies to behave in roughly the same way rather than having subtle differences.
* Rename AssociationProxy#foreign_key_present to foreign_key_present?Jon Leighton2011-01-031-1/+1
|
* Allow assignment on has_one :through where the owner is a new record [#5137 ↵Jon Leighton2011-01-031-13/+7
| | | | | | | | | | state:resolved] This required changing the code to keep the association proxy for a belongs_to around, despite its target being nil. Which in turn required various changes to the way that stale target checking is handled, in order to support various edge cases (loaded target is nil then foreign key added, foreign key is changed and then changed back, etc). A side effect is that the code is nicer and more succinct. Note that I am removing test_no_unexpected_aliasing since that is basically checking that the proxy for a belongs_to *does* change, which is the exact opposite of the intention of this commit. Also adding various tests for various edge cases and related things. Phew, long commit message!