Commit Graph

116 Commits

Author SHA1 Message Date
Jon Leighton
d5e63b1a01 Fix #3271.
Building the conditions of a nested through association could
potentially modify the conditions of the through and/or source
association.

This is a Bad Thing.

Conflicts:

	activerecord/test/cases/reflection_test.rb
2011-11-03 15:12:47 +00:00
Jon Leighton
f8beca00dc Raise an exception on unknown primary key inside AssociationReflection.
An association between two models cannot be made if a relevant key is
unknown, so fail fast rather than generating invalid SQL. Fixes #3207.
2011-10-05 20:24:45 +01:00
Jon Leighton
45c56bdd2d Don't call self.class unless necessary. Closes #3171. 2011-09-29 18:00:48 +01:00
Jon Leighton
4aeb7f2eb7 Fix belongs_to polymorphic with custom primary key on target.
Closes #3104.
2011-09-26 15:43:04 +01:00
Jon Leighton
a48e332f7b Ensure we are not comparing a string with a symbol in HasManyAssociation#inverse_updates_counter_cache?. Fixes #2755, where a counter cache could be decremented twice as far as it was supposed to be. 2011-09-06 16:06:43 +01:00
Aaron Patterson
37eef89a2b calling super is super. if the other object is exactly equal, we can return early 2011-07-01 14:39:13 -07:00
Jon Leighton
92c68dabd5 Add an extremely lulzy deprecation warning which tries to detect if AssociationReflection#build_association has been overridden, but ignores the block argument. 2011-06-30 23:39:43 +01:00
Jon Leighton
65813a6317 Assign the association attributes to the associated record before the before_initialize callback of the record runs. Fixes #1842. 2011-06-30 23:39:43 +01:00
Jon Leighton
da9c79b693 Remove AssociationReflection#create_association and AssociationReflection#create_association! - they are not called from anywhere. 2011-06-30 23:39:43 +01:00
Aaron Patterson
68b8710f8d cache the plural name on the reflection so we do not pay pluralize costs on joins 2011-06-30 15:32:34 -07:00
Jon Leighton
872a9c1b50 Fix problem with loading polymorphic associations which have been defined in an abstract superclass. Fixes #552. 2011-05-23 20:30:26 +01:00
Prem Sichanugrist
733bfa63f5 Remove #among? from Active Support
After a long list of discussion about the performance problem from using varargs and the reason that we can't find a great pair for it, it would be best to remove support for it for now.

It will come back if we can find a good pair for it. For now, Bon Voyage, `#among?`.
2011-04-13 20:25:28 +08:00
David Heinemeier Hansson
d1575ae1b9 Change Object#either? to Object#among? -- thanks to @jamesarosen for the suggestion! 2011-04-12 00:23:07 +02:00
Prem Sichanugrist
a9f3c9da01 Using Object#in? and Object#either? in various places
There're a lot of places in Rails source code which make a lot of sense to switching to Object#in? or Object#either? instead of using [].include?.
2011-04-11 03:17:09 +08:00
Jon Leighton
39a6f4f25d Simplify implementation of ThroughReflection#chain 2011-03-11 00:51:57 +00:00
Jon Leighton
2d3d9e3531 Rename Reflection#through_reflection_chain and #through_options to Reflection#chain and Reflection#options as they now no longer relate solely to through associations. 2011-03-10 19:28:26 +00:00
Jon Leighton
6490d65234 Move the code which builds a scope for through associations into a generic AssociationScope class which is capable of building a scope for any association. 2011-03-10 19:04:00 +00:00
Jon Leighton
bb063b2f1b Fix test_has_many_association_through_a_has_many_association_with_nonstandard_primary_keys 2011-03-07 20:58:32 +00:00
Jon Leighton
5dc1fb39dd Refactor ThroughAssociation#join_to to be much smaller, and independent of construct_owner_conditions. 2011-03-06 23:38:10 +00:00
Jon Leighton
7fddb94262 Push source_type and polymorphic conditions out of ThroughAssociation and JoinDependency::JoinAssociation and into the reflection instead. 2011-03-05 22:07:30 +00:00
Jon Leighton
ddf83d14f1 Add a test for STI on the through where the through is nested, and change the code which support this 2011-03-05 20:10:24 +00:00
Jon Leighton
735844db71 Merge branch 'master' into nested_has_many_through
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
2011-03-04 09:30:27 +00:00
Jon Leighton
d90b4e2615 Rewrote AssociationPreload. 2011-02-28 22:12:34 +00:00
Jon Leighton
32eef69dc1 Delegate Association#options to the reflection, and replace 'reflection.options' with 'options'. Also add through_options and source_options methods for through associations. 2011-02-21 10:16:14 -08:00
Jon Leighton
1644663ba7 Split AssociationProxy into an Association class (and subclasses) which manages the association, and a CollectionProxy class which is *only* a proxy. Singular associations no longer have a proxy. See CHANGELOG for more. 2011-02-18 00:00:13 +00:00
Jon Leighton
f0b9805029 Ensure that association_ids uses the correct attribute where the association is a has_many :through with a :primary_key option on the source reflection. [#6376 state:resolved] 2011-02-18 00:00:13 +00:00
Jon Leighton
3b797c8c86 DRY up the code which instantiates the association proxy 2011-01-11 13:45:08 -08:00
Jon Leighton
0619dc2319 Implement deprecated version of AssociationReflection#primary_key_name, which has been renamed to #foreign_key. Also bumping the deprecation_horizon in Active Support to 3.1. 2011-01-03 16:24:32 -08:00
Jon Leighton
c47f802d0e Have a proper AssociationReflection#foreign_type method rather than using options[:foreign_type] 2011-01-03 16:24:31 -08:00
Jon Leighton
1267598881 Rename AssociationReflection#primary_key_name to foreign_key, since the options key which it relates to is :foreign_key 2010-12-31 20:00:45 +00:00
Jon Leighton
b0bb911fa1 Now we can drop-kick AssociationReflection#dependent_conditions into oblivion. 2010-12-31 20:00:44 +00:00
Jon Leighton
fb3a8c51b4 Raise an error for associations which try to go :through a polymorphic association [#6212 state:resolved] 2010-12-23 15:19:18 -08:00
Jon Leighton
2d9626fc74 Improved strategy for updating a belongs_to association when the foreign key changes. Rather than resetting each affected association when the foreign key changes, we should lazily check for 'staleness' (where fk does not match target id) when the association is accessed. 2010-12-23 15:19:18 -08:00
Jon Leighton
c6db37e69b Don't allow a has_one association to go :through a collection association [#2976 state:resolved] 2010-12-23 15:19:17 -08:00
Jon Leighton
b8153fd5a1 Fix problem where wrong keys are used in JoinAssociation when an association goes :through a belongs_to [#2801 state:resolved] 2010-12-20 13:56:04 -08:00
Jon Leighton
14b880fd03 Fix various issues with the :primary_key option in :through associations [#2421 state:resolved] 2010-12-15 17:50:14 -08:00
Aaron Patterson
b3ae67dbb9 reduce method calls 2010-12-16 01:49:28 +05:30
Jon Leighton
9a98c766e0 Merge branch 'master' into nested_has_many_through
Conflicts:
	activerecord/CHANGELOG
	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_through_association.rb
2010-12-12 09:55:32 +00:00
Aaron Patterson
9e16254b46 reduce method calls 2010-12-10 16:31:09 -08:00
Jon Leighton
3a7f43ca6e Merge branch 'master' into nested_has_many_through
Conflicts:
	activerecord/CHANGELOG
	activerecord/lib/active_record/associations.rb
2010-11-27 11:31:17 +00:00
Josh Kalderimis
d7db6a8873 class inheritable attributes is used no more! all internal use of class inheritable has been changed to class_attribute. class inheritable attributes has been deprecated.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-20 19:40:29 +01:00
Jon Leighton
9a1a32ac2b Fix naughty trailing whitespace 2010-10-31 11:21:28 +00:00
Jon Leighton
fc276e5635 Merge branch 'master' into nested_has_many_through
Conflicts:
	activerecord/CHANGELOG
	activerecord/lib/active_record/association_preload.rb
	activerecord/lib/active_record/associations.rb
	activerecord/test/schema/schema.rb
2010-10-28 18:06:01 +01:00
Aaron Patterson
828bb94d5a use grep instead of select + is_a? 2010-10-20 16:41:50 -07:00
Jon Leighton
2aa9388746 Add some comments for ThroughReflection#through_reflection_chain 2010-10-19 17:40:14 +01:00
Jon Leighton
7ee33b80a2 Remove various comments and code which were just being used during the development of nested through association support (OMFGZ, I might just have nearly finished this\! 2010-10-19 17:29:19 +01:00
Jon Leighton
82b889f7d3 Add explicit tests for the nested through association changes in reflection.rb 2010-10-19 17:22:42 +01:00
Jon Leighton
0ceb342955 Bugfix/refactoring 2010-10-19 15:24:30 +01:00
Jon Leighton
9ff5fdeda9 Remove unused methods 2010-10-19 14:56:59 +01:00
Jon Leighton
01838636c6 Support for :primary_key option on the source reflection of a through association, where the source is a has_one or has_many 2010-10-19 14:14:06 +01:00