Commit Graph

2497 Commits

Author SHA1 Message Date
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
Akira Matsuda
817e370136 Make before_type_cast available for datetime fields
[#3973 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-02-01 12:21:18 -02:00
Pratik Naik
9666b6a625 Run BulkAlterTableMigrationsTest only when the adapter supports them 2011-01-31 14:10:51 +00:00
Pratik Naik
30176f28a4 Add :bulk => true option to change_table 2011-01-31 13:21:25 +00: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
2e24cf7cc2 AssociationCollection#clear can basically just use #delete_all, except it should return self. 2011-01-30 11:58:08 +00:00
Jon Leighton
88df88095c AssociationCollection#to_ary should definitely dup the target! Also changed #replace which was previously incorrect, but the test passed due to the fact that to_a was not duping. 2011-01-30 11:58:08 +00:00
Jon Leighton
b7bcc7e190 DRY up first/last and hence make last benefit from the bugfix in first 2011-01-30 11:58:08 +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
Alexey Nayden
fa779c5357 Fixing incorrectly writtent testcase 2011-01-28 15:06:02 -08:00
Alexey Nayden
2884482c34 test_first_and_array_index_zero_methods_return_the_same_value_when_nested_attributes_are_set_to_update_existing_record added 2011-01-28 15:06:01 -08:00
Aaron Patterson
e6881217ed fixing bug where 1.8 hangs while running pg tests 2011-01-18 10:49:50 -08:00
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