Aaron Patterson
fdfabc99e8
fixing unused variable warnings
2011-01-17 14:22:17 -08:00
Jon Leighton
d1521719c5
Removed support for accessing attributes on a has_and_belongs_to_many join table. This has been documented as deprecated behaviour since April 2006. Please use has_many :through instead. A deprecation warning will be added to the 3-0-stable branch for the 3.0.4 release.
2011-01-16 13:43:54 -08: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
Aaron Patterson
2947197421
use rake to create test databases for us
2011-01-14 14:07:16 -08:00
Aaron Patterson
f30a3106f3
transactional fixtures must be set to false for this test
2011-01-14 13:45:30 -08:00
Aaron Patterson
1e9685f159
preheat the table cache in arel
2011-01-14 11:16:31 -08:00
Santiago Pastorino
3755ae04a1
Add missing require
2011-01-14 17:11:15 -02:00
Aaron Patterson
3165dca28c
include_in_memory? should check against @target list in case of new records. [ #6257 state:resolved]
2011-01-12 18:07:53 -08:00
Aaron Patterson
f8700038af
adding a test for no method error
2011-01-11 17:57:02 -08:00
Aaron Patterson
fcd8925f23
use underlying _read_attribute method rather than causing NoMethodErrors
2011-01-11 15:39:26 -08:00
Jon Leighton
552df9b933
Support for create_association! for has_one associations
2011-01-11 13:45:09 -08:00
Jon Leighton
681ab53ba1
Get rid of set_association_target and association_loaded? as the parts of the code that need that can now just use association_proxy(:name).loaded?/target=
2011-01-11 13:45:08 -08:00
Jon Leighton
3b797c8c86
DRY up the code which instantiates the association proxy
2011-01-11 13:45:08 -08:00
Jon Leighton
6055bbedaa
Raise ActiveRecord::RecordNotSaved if an AssociationCollection fails to be replaced
2011-01-11 13:45:07 -08:00
Jon Leighton
1d6e218428
When assigning a has_one, if anything fails, the assignment should be rolled back entirely
2011-01-11 13:45:07 -08:00
Jon Leighton
4e19ec566c
In a number of places in the tests, we only need to turn off transactional fixtures when the DB does not support savepoints. This speeds the test run up by about 8-9% on my computer, when running rake test_sqlite3_mem :)
2011-01-11 13:45:07 -08:00
Jon Leighton
7f7b480098
When assigning a has_one, if the new record fails to save, raise an error
2011-01-11 13:45:07 -08:00
Jon Leighton
1bc71ed960
When assigning a has_one, if the existing record fails to be removed from the association, raise an error
2011-01-11 13:45:06 -08:00
Jon Leighton
c47c541402
Have a separate test connection directory for sqlite3 in-memory so that the tests can be run without having to specifically rename the connection file (which then causes git to pick up the changes)
2011-01-11 13:45:06 -08:00
Jon Leighton
80df74bf51
Enable the sqlite3 in-memory test connection to work
2011-01-11 13:45:06 -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
Raimonds Simanovskis
f4f4964ce0
Always return decimal average of integer fields
...
In previous version if database adapter (e.g. SQLite and Oracle) returned non-String calculated values then type_cast_using_column converted decimal average value of intefer field to integer value. Now operation parameter is always checked to decide which conversion of calculated value should be done.
2011-01-10 15:51:32 -08:00
Aaron Patterson
0616585619
use SQLite3::VERSION rather than the deprecated class
2011-01-10 11:40:19 -08:00
Jeremy Kemper
63ed6ca998
Add test for e0e3adf
2011-01-07 16:25:25 -08:00
Jon Leighton
5b28e52542
Don't not remove double negatives
2011-01-07 15:03:16 -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
Jon Leighton
441118458d
Use encode_with for marshalling
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
Aaron Patterson
839f3bf682
just use a hash for doing association caching
2011-01-07 11:28:11 -08:00
Aaron Patterson
eba8411652
adding an encode_with method for Psych dump/load methods
2011-01-05 14:59:19 -08:00
Aaron Patterson
97bc74c746
make sure new objects can round trip
2011-01-05 14:03:13 -08:00
Aaron Patterson
6d74710828
make sure that Psych can roundtrip an AR object
2011-01-05 14:01:47 -08:00
Aaron Patterson
3f4143eedb
fixing merge errors
2011-01-04 15:16:56 -08:00
Jon Leighton
40afcade0d
Remove undocumented feature from has_one where you could pass false as the second parameter to build_assoc or create_assoc, and the existing associated object would be untouched (the foreign key would not be nullified, and it would not be deleted). If you want behaviour similar to this you can do the following things:
...
* Use :dependent => :nullify (or don't specify :dependent) if you want to prevent the existing associated object from being deleted
* Use has_many if you actually want multiple associated objects
* Explicitly set the foreign key if, for some reason, you really need to have multiple objects associated with the same has_one. E.g.
previous = obj.assoc
obj.create_assoc
previous.update_attributes(:obj_id => obj.id)
2011-01-03 16:24:32 -08:00
Jon Leighton
2120da7f73
ActiveRecord::Relation#primary_key should return a string, just like ActiveRecord::Base.primary_key does.
2011-01-03 16:24:32 -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
a9bed985cf
When preloading a belongs_to, the target should still be set (to nil) if there is no foreign key present. And the loaded flag should be set on the association proxy. This then allows us to remove the foreign_key_present? check from BelongsToAssociation#find_target. Also added a test for the same thing on polymorphic associations.
2011-01-03 16:24:32 -08:00
Jon Leighton
1313d386da
Make Relation#create_with always merge rather than overwrite, not just when merging two relations. If you wish to overwrite, you can do relation.create_with(nil), or for a specific attribute, relation.create_with(:attr => nil).
2011-01-03 16:24:32 -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
d6289aadce
Fix test_any in relations_test.rb, which was failing when relations_test.rb is run on its own (it passes when the entire suite is run). This is a hacky fix for a problem I didn't quite get to the bottom of, so I'd welcome a better solution...
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
c47f802d0e
Have a proper AssociationReflection#foreign_type method rather than using options[:foreign_type]
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
Aaron Patterson
60cf65def8
herp derpricating add_limit_offset!
2011-01-03 15:59:13 -08:00
Robert Pankowecki (Gavdi)
febdf5a5a9
Added one more failing test for bug #6036
2011-01-04 01:21:25 +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
3c400627eb
Support for :counter_cache on polymorphic belongs_to
2010-12-31 20:00:44 +00:00
Jon Leighton
bea4065d3c
Refactor BelongsToAssociation to allow BelongsToPolymorphicAssociation to inherit from it
2010-12-31 20:00:44 +00:00