Jon Leighton
9abc94c445
oracle, y u defy me
2011-03-16 18:54:34 +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
91fd651056
Allow building and then later saving has_many :through records, such that the join record is automatically saved too. This requires the :inverse_of option to be set on the source association in the join model. See the CHANGELOG for details. [ #4329 state:resolved]
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
a7e19b30ca
Add interpolation of association conditions back in, in the form of proc { ... } rather than instance_eval-ing strings
2011-02-14 01:40:31 +00:00
Jan
9643243204
make set_table_name take effect immediately
2011-02-08 10:31:09 -08:00
Jon Leighton
52f09eac5b
Correctly update counter caches on deletion for has_many :through [ #2824 state:resolved]. Also fixed a bunch of other counter cache bugs in the process, as once I fixed this one others started appearing like nobody's business.
2011-02-07 23:35:05 +00:00
Jon Leighton
05bcb8cecc
Support the :dependent option on has_many :through associations. For 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.
2011-02-07 23:35:05 +00:00
Edward Faulkner
909588d964
Fixing ordering of HABTM association deletion [ #6191 state:resolved]
...
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com >
2011-02-04 19:39:59 -02:00
Aaron Patterson
df07760486
introduce a fake AR adapter for mocking database return values
2011-02-04 13:34:57 -08:00
Aaron Patterson
ee34b4cf34
share column cache among subclasses, only look up columns per AR::Base subclass once
2011-02-01 14:25:46 -08:00
Glenn Vanderburg
6bd9fac1e3
Propagate association extensions to scopes called on the association.
...
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com >
2011-02-01 12:38:58 -02:00
Jon Leighton
3fa61ccb9e
Has many through - It is not necessary to manually merge in the conditions hash for the through record, because the creation is done directly on the through association, which will already handle setting the conditions.
2011-01-30 11:58:09 +00:00
Jon Leighton
63c73dd021
We shouldn't be using scoped.scoping { ... } to build associated records, as this can affect validations/callbacks/etc inside the record itself [ #6252 state:resolved]
2011-01-30 11:56:41 +00:00
Jon Leighton
bf24fe810c
belongs_to records should be initialized within the association scope
2011-01-16 13:43:53 -08:00
Jon Leighton
52c47556b7
Add create_association! for belongs_to
2011-01-16 13:43:53 -08:00
Jon Leighton
3b797c8c86
DRY up the code which instantiates the association proxy
2011-01-11 13:45:08 -08:00
Jon Leighton
c6e10b0f60
has_one should always remove the old record (properly), even if not saving the new record, so we don't get the database into a pickle
2011-01-11 13:45:06 -08:00
Ernie Miller
7d4d745730
Fix polymorphic belongs_to associationproxy raising errors when loading target.
2011-01-11 09:19:19 -08:00
Jon Leighton
770e6893b9
Construct an actual ActiveRecord::Relation object for the association scope, 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.
2011-01-07 15:03:15 -08:00
Aaron Patterson
2efd780dcb
send() will raise an ArgumentError, so we should leverage ruby
2011-01-07 14:30:20 -08:00
Jon Leighton
3103296a61
Let AssociationCollection#find use #scoped to do its finding. Note that I am 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.
2011-01-03 16:24:31 -08:00
Jon Leighton
a0be389d39
Allow assignment on has_one :through where the owner is a new record [ #5137 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!
2011-01-03 16:24:31 -08:00
Jon Leighton
16065b4f19
Some basic tests for the :foreign_type option on belongs_to, which was previously completely untested.
2011-01-03 16:24:30 -08:00
Jon Leighton
2bf3186803
Verify that when has_many associated objects are destroyed via :dependent => :destroy, when the parent is destroyed, the callbacks are run
2010-12-31 20:00:44 +00:00
Pratik Naik
573fd39e22
Make sure Model#touch doesn't try to update non existing columns
2010-12-30 18:42:18 +00:00
Pratik Naik
fd1cf13f74
Make serialized fixtures work again
2010-12-29 16:15:45 +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
3f17ed407c
Test to verify that #2189 (count with has_many :through and a named_scope) is fixed
2010-12-23 15:19:18 -08:00
Szymon Nowak
85683f2a79
Fix creation of has_many through records with custom primary_key option on belongs_to [ #2990 state:resolved]
2010-12-23 15:19:17 -08:00
Will Bryant
b79823832e
Verify that has_one :through preload respects the :conditions [ #2976 state:resolved]
2010-12-23 15:19:17 -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
Aaron Patterson
3e64336647
removing SQL interpolation, please use scoping and attribute conditionals as a replacement
2010-12-22 18:23:38 -08:00
Jon Leighton
834e5336a5
has_many associations with :dependent => :delete_all should update the counter cache when deleting records
2010-12-20 13:56:04 -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
Jon Leighton
491ce5b6ce
Verify that creating a has_many through record where there is a default_scope on the join model works correctly (creates the join record with the default scope applied)
2010-12-16 01:49:30 +05:30
Jon Leighton
eba7664086
Respect the default_scope on a join model when reading a through association
2010-12-16 01:49:30 +05:30
Ernie Miller
5d37ff6bb2
Fix hm:t to self table aliasing in construct_scope
2010-12-16 01:49:29 +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
542cb5c327
fix warnings, stop using global variables
2010-11-30 18:46:56 -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
Neeraj Singh
66212f69ac
If a nested_attribute is being marked for destruction and at the same time an attr_accessor value is being assigned then the value being assigned is being ignored. This patch is a fix for that issue.
...
[#5939 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com >
2010-11-24 22:08:36 +01:00
Jon Leighton
1bc90044b6
Merge branch 'master' into nested_has_many_through
...
Conflicts:
activerecord/lib/active_record/associations/has_many_through_association.rb
activerecord/test/cases/associations/has_many_through_associations_test.rb
2010-11-17 11:32:31 +00:00
David Chelimsky
1f06652a57
use persisted? instead of new_record? wherever possible
...
- persisted? is the API defined in ActiveModel
- makes it easier for extension libraries to conform to ActiveModel APIs
without concern for whether the extended object is specifically
ActiveRecord
[#5927 state:committed]
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com >
2010-11-09 13:54:04 -02:00
Jon Leighton
9a1a32ac2b
Fix naughty trailing whitespace
2010-10-31 11:21:28 +00:00
Jon Leighton
d010fb13ef
Merge branch 'master' into nested_has_many_through
...
Conflicts:
activerecord/lib/active_record/associations/has_many_association.rb
activerecord/lib/active_record/associations/through_association_scope.rb
2010-10-31 10:04:56 +00:00
Denis Odorcic
cc9742920c
Convert :primary_key in association to a string before comparing to column names, so that for example :primary_key => :another_pk works as well [ #5605 state:resolved]
2010-10-30 11:24:36 -07:00