Commit Graph

295 Commits

Author SHA1 Message Date
Jon Leighton
e6cc2ea201 Allow the :class_name option for associations to take a symbol.
This is to avoid confusing newbies, and to be consistent with the fact
that other options like :foreign_key already allow a symbol or a string.
2011-11-04 11:17:56 +00:00
Jeremy Kemper
0a9b6de4d2 Tests gotta run in 1.8 too 2011-10-13 15:54:53 -07:00
David Heinemeier Hansson
85b64f98d1 Added ActiveRecord::Base.store for declaring simple single-column key/value stores [DHH] 2011-10-13 16:24:22 -05:00
Jon Leighton
50d395f96e Raise error when using write_attribute with a non-existent attribute.
Previously we would just silently write the attribute. This can lead to
subtle bugs (for example, see the change in AutosaveAssociation where a
through association would wrongly gain an attribute.

Also, ensuring that we never gain any new attributes after
initialization will allow me to reduce our dependence on method_missing.
2011-09-13 00:01:58 +01:00
Jon Leighton
8667d3aeb6 Make protected method public so we avoid method_missing. 2011-09-13 00:01:58 +01:00
Jon Leighton
b24d668859 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 15:58:07 +01:00
Arun Agrawal
9066e34025 We need to recorder here. Need to drop the order from default scope.
Fixes #2832
2011-09-05 00:12:57 +05:30
Jon Leighton
735d985b01 The join_nodes must be passed to the JoinDependency initializer and therefore counted by the alias tracker. This is because the association_joins are aliased on initialization and then the tables are cached, so it is no use to alias the join_nodes later. Fixes #2556. 2011-08-29 15:05:47 +01:00
Jon Leighton
24f902b1bc Fix default scope thread safety. Thanks @thedarkone for reporting. 2011-08-13 16:54:05 +01:00
Gabriel Horner
f5e4d13270 use existing model for testing Base.create with #after_initialize 2011-07-24 16:36:06 -04:00
Gabriel Horner
6e3c0a5d9a simplify and be more explicit about create and after_initialize tests 2011-07-24 00:31:37 -04:00
Les Fletcher
f956759f8a fix after_initialize edge case (close #2074 and close #2175)
fix behavior when after_initialize is defined and a block is passed to Base.create
2011-07-24 00:31:28 -04:00
Jon Leighton
1712d90050 Fix exception if old and new targets are both nil. Fixes #1471. 2011-07-12 00:14:45 +01:00
Jon Leighton
0e225ec583 Assign the association attributes to the associated record before the before_initialize callback of the record runs. Fixes #1842. 2011-06-30 23:39:58 +01:00
Jon Leighton
87d6865bf7 Apply the default scope earlier when doing calculations. Fixes #1682. 2011-06-23 19:57:49 +01:00
Andrew White
5d655aabcb Pass mass-assignment options to nested models - closes #1673. 2011-06-13 13:02:51 +01:00
Jon Leighton
14e6bbb149 Refactor tests to be less brittle 2011-06-12 18:19:21 +01:00
Arun Agrawal
0695eb6dac Test added for namedscope target. 2011-06-03 08:28:00 +05:30
Erik Fonselius
a5806fa409 Failing test for aggregating on default_scope with select 2011-05-31 20:47:30 +01:00
Farley Knight
aa316e27b7 Tests for issue #1360 2011-05-31 19:47:34 +01:00
Jon Leighton
c69111ba5f Fix infinite recursion where a lazy default scope references a scope. Fixes #1264. 2011-05-25 00:08:14 +01:00
Jon Leighton
ce37f747cd Merge pull request #1254 from pixeltrix/ignore-includes-in-through-scope
Ignore :includes on through associations
2011-05-24 15:34:28 -07:00
Andrew White
f1f1ab77df Failing tests for #1233. 2011-05-24 23:25:21 +01:00
Andrew White
d8bd19f6ab Ignore :includes on through associations 2011-05-24 07:21:32 +01:00
Guillermo Iguaran
23e94a67f8 Refactoring test_has_many_with_pluralize_table_names_false test 2011-05-20 01:53:13 -05:00
Andrew White
42f1ad6865 Pass the attribute and option hashes to build_association
The build_association method was added as an API for plugins
to hook into in 1398db0. This commit restores this API and the
ability to override class.new to return a subclass based on
a virtual attribute in the attributes hash.
2011-05-17 20:43:30 +01:00
Jon Leighton
2033ff825b Merge pull request #560 from guilleiguaran/fix_pluralize_table_names_false
Fixing has_many when ActiveRecord::Base.pluralize_table_names is false
2011-05-16 15:40:12 -07:00
Guillermo Iguaran
ecbde46e57 Fixing has_many association when ActiveRecord::Base.pluralize_table_names is false. fixes #557 2011-05-15 03:53:10 -05:00
Jon Leighton
60b23ea1da CollectionAssociation#merge_target_lists should write to the underlying attributes when copying, rather than using the assignment method 2011-05-14 19:49:22 +01:00
Jon Leighton
6e466f17c3 Don't use mass-assignment protection when setting foreign keys or association conditions on singular associations. Fixes #481 (again). 2011-05-12 23:29:22 +01:00
Jon Leighton
1dd90f8f12 Don't use select() values from the join model of a through association. Fixes #508. 2011-05-11 08:56:01 +01:00
Jon Leighton
a8c1fa4afd Add test to specify that attributes from an association's conditions should be assigned without mass-assignment protection when a record is built on the association. 2011-05-10 23:35:15 +01:00
Christopher Meiklejohn
4fbd8adf48 Don't quote ID's as Arel will quote them -- follow same conventions as the delete method. 2011-05-08 18:37:28 +01:00
David Heinemeier Hansson
a8861c8f5b Merge pull request #357 from joshk/assign_attributes.
Assign protected attributes with create/new and control the role.
2011-05-01 16:59:33 -07:00
Josh Kalderimis
86d7ed3375 singular and collection relations in AR can now specify mass-assignment security options (:as and :without_protection) in build, create and create! methods. 2011-05-01 23:30:07 +02:00
Josh Kalderimis
5164c50d7f removed the default_scope deprecations and updated the docs and tests to reflect its use cases 2011-04-28 18:46:40 +02:00
Josh Kalderimis
a08d04bedf Added assign_attributes to Active Record which accepts a mass-assignment security scope using the :as option, while also allowing mass-assignment security to be bypassed using :with_protected 2011-04-24 09:53:18 +02:00
Jon Leighton
019cd51a3f Bring back support for passing a callable object to the default_scope macro. You can also just use a block. 2011-04-18 23:35:22 +01:00
Jon Leighton
6f84c73dc4 Un-deprecate using 'default_scope' as a macro, but if you are calling the macro multiple times that will give deprecation warnings, and in 3.2 we will simply overwrite the default scope when you call the macro multiple times. 2011-04-18 23:15:38 +01:00
Jon Leighton
256b363eee Revert "Deprecate defining scopes with a callable (lambda, proc, etc) via the scope class method. Just define a class method yourself instead."
This reverts commit f0e198bfa1e3f9689e0cde1d194a44027fc90b3c.

Conflicts:

	activerecord/test/models/post.rb
2011-04-17 20:47:52 +01:00
Aaron Patterson
1b5b53da5e common @jonleighton 💣 2011-04-12 20:29:35 -07:00
Jon Leighton
f0e198bfa1 Deprecate defining scopes with a callable (lambda, proc, etc) via the scope class method. Just define a class method yourself instead. 2011-04-12 19:46:05 -07:00
Jon Leighton
8572ae6671 Evaluate default scopes at the last possible moment in order to avoid problems with default scopes getting included into other scopes and then being unable to remove the default part via unscoped. 2011-04-12 19:46:04 -07:00
Jon Leighton
5740d4ec0c Deprecated support for passing hashes and relations to default_scope, in favour of defining a 'default_scope' class method in the model. See the CHANGELOG for more details. 2011-04-12 19:46:04 -07:00
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