Commit Graph

20352 Commits

Author SHA1 Message Date
Jon Leighton
45d0d18bae Not really worth having the HasAssociation module for just a single method 2011-01-07 15:03:15 -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
6e63e7a874 no need for parens 2011-01-07 14:10:46 -08:00
Aaron Patterson
344a2d5adc use a hash for caching aggregations rather than ivars 2011-01-07 13:53:34 -08:00
Aaron Patterson
f3d92f0756 method is never called with arguments 2011-01-07 13:41:38 -08:00
Aaron Patterson
2ee4c8d90b only rescue from Mysql::Error exceptions [#6236 state:resolved] 2011-01-07 11:48:29 -08:00
Aaron Patterson
839f3bf682 just use a hash for doing association caching 2011-01-07 11:28:11 -08:00
Aaron Patterson
8a1c533780 no need for self 2011-01-06 15:15:36 -08:00
Nick Sutterer
7773c32400 corrected docs for Hash#to_xml and added examples. 2011-01-06 17:57:09 +01:00
Nick Sutterer
54f3aa8633 added tests for XmlMini#to_tag. 2011-01-06 17:56:22 +01: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
9731c862ec AR internals expect a normal hash, otherwise there are serialization incompatibilities 2011-01-05 13:50:08 -08:00
Aaron Patterson
64c82f9ec6 only define log_level reader once, make sure to initialize @log_level 2011-01-05 11:19:09 -08:00
Aaron Patterson
c7dce2c7b2 no need to specify self 2011-01-05 11:08:21 -08:00
Aaron Patterson
102255330b no need to send a symbol to send() 2011-01-05 10:50:46 -08:00
Aaron Patterson
90171ad833 avoid creating so many Arel::Table objects 2011-01-05 10:29:06 -08:00
Aaron Patterson
9f1b0b32e2 use attr_reader and alias methods to access instance variables 2011-01-05 09:58:25 -08:00
Aaron Patterson
8bdc191994 we have a method for this, so let's use it 2011-01-05 09:51:09 -08:00
Aaron Patterson
e468a62dc8 use arel ast construction rather than generating strings 2011-01-05 09:47:13 -08:00
Aaron Patterson
35a225535f use arel to construct AST rather than generate strings 2011-01-05 09:23:30 -08:00
Hemant Kumar
8de5595e4d fix difference between behaviour of blank and empty
Signed-off-by: José Valim <jose.valim@gmail.com>
2011-01-05 13:18:10 +01:00
Aaron Patterson
5c66677987 make our yaml output consistent 2011-01-04 17:29:40 -08:00
Aaron Patterson
7bd32e4d1d add Psych::SyntaxError to the list of rescued YAML exceptions 2011-01-04 16:52:47 -08:00
Aaron Patterson
3f4143eedb fixing merge errors 2011-01-04 15:16:56 -08:00
Aaron Patterson
3f7e097464 Merge remote branch 'rsim/require_deprecation'
* rsim/require_deprecation:
  require ActiveSupport deprecatation file before using deprecate method in database_statements
2011-01-04 15:09:22 -08:00
Aaron Patterson
c08fccf980 Merge remote branch 'rsim/habtm_select_fix'
* rsim/habtm_select_fix:
  Explicitly select * from has_and_belongs_to_many association tables, simplify exists? query
2011-01-04 15:08:28 -08:00
Aaron Patterson
4fabad7cf1 test that the custom ordered hash can be round-tripped 2011-01-04 15:07:15 -08:00
Aaron Patterson
a84b84efac require Psych if possible, use Psych output when enabled 2011-01-04 15:07:15 -08:00
Aaron Patterson
b1dc9c004e use dots for method calls 2011-01-04 15:07:15 -08:00
Pratik Naik
a8a704b07c Bump rack-test version 2011-01-04 19:30:52 +00:00
Prem Sichanugrist
4805ec1449 Add test cases for model and migration generators which use change method. 2011-01-04 11:17:07 -08:00
Prem Sichanugrist
ad343d7263 Use Rails 3.1 change method in 'add_' migration generator 2011-01-04 11:16:52 -08:00
Prem Sichanugrist
9e64dfad0d Use Rails 3.1 change method in model generator 2011-01-04 11:16:52 -08:00
Raimonds Simanovskis
9c1c551f25 Explicitly select * from has_and_belongs_to_many association tables, simplify exists? query
Previous version (after commit 3103296a61) was generating wrong SQL for Oracle when calling exists? method on HABTM association.
2011-01-04 17:06:33 +02:00
Raimonds Simanovskis
1d758d9086 require ActiveSupport deprecatation file before using deprecate method in database_statements
otherwise when using external ActiveRecord adapters (e.g. Oracle) database_statements might be loaded before active_support/core_ext/module/deprecation which results in NoMethodError (commit 60cf65def8 added "deprecate" call to database_statements.rb)
2011-01-04 11:21:03 +02: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
99a8d8430f Create the association scope directly rather than going through with_scope 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
31d101879f Use the association directly in other places too 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
4e194ed1e6 Rename AssociationProxy#foreign_key_present to foreign_key_present? 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