Commit Graph

78 Commits

Author SHA1 Message Date
Kelsey Schlarman
43675f014c Calling reset on a collection association should unload the assocation
Need to define #reset on CollectionProxy.
2014-01-21 18:24:28 -08:00
Aaron Patterson
f25251b573 do is_a? tests on assignment so runtime is faster 2013-07-31 18:19:36 -07:00
Vipul A M
4237d74213 Fix typo in test name and documentation 2013-05-20 10:35:43 +05:30
Jon Leighton
d7abe91cc7 Set the inverse when association queries are refined
Suppose Man has_many interests, and inverse_of is used.

Man.first.interests.first.man will correctly execute two queries,
avoiding the need for a third query when Interest#man is called. This is
because CollectionAssociation#first calls set_inverse_instance.

However Man.first.interests.where("1=1").first.man will execute three
queries, even though this is obviously a subset of the records in the
association.

This is because calling where("1=1") spawns a new Relation object from
the CollectionProxy object, and the Relation has no knowledge of the
association, so it cannot set the inverse instance.

This commit solves the problem by making relations spawned from
CollectionProxies return a new Relation subclass called
AssociationRelation, which does know about associations. Records loaded
from this class will get the inverse instance set properly.

Fixes #5717.

Live commit from La Conf! 
2013-05-10 10:36:26 +02:00
Anupam Choudhury
8ed04e90d2 Removed space and unused class 2013-04-06 02:35:15 +05:30
Jon Leighton
133a1759a4 Cache the association proxy object
This reimplements the behaviour of Rails 3, as I couldn't see why we
shouldn't cache the object, and @alindeman had a good use case for
caching it:

c86a32d745 (commitcomment-2784312)
2013-03-15 13:48:45 +00:00
Vipul A M
d338a0feaf MOAR cleanups. 2013-03-14 10:47:13 +05:30
Yves Senn
b9399c470b deal with #append and #prepend on association collections.
Closes #7364.

Collection associations behave similar to Arrays. However there is no
way to prepend records. And to append one should use `<<`. Before this
patch `#append` and `#prepend` did not add the record to the loaded
association.

`#append` now behaves like `<<` and `#prepend` is not defined.
2013-03-01 21:29:46 +01:00
Steve Klabnik
22df38ca33 Ensure that associations have a symbol argument.
Fixes #7418.
2012-11-28 13:39:42 -08:00
Jon Leighton
0e1cafcbc4 Add CollectionProxy#scope
This can be used to get a Relation from an association.

Previously we had a #scoped method, but we're deprecating that for
AR::Base, so it doesn't make sense to have it here.

This was requested by DHH, to facilitate code like this:

    Project.scope.order('created_at DESC').page(current_page).tagged_with(@tag).limit(5).scoping do
      @topics      = @project.topics.scope
      @todolists   = @project.todolists.scope
      @attachments = @project.attachments.scope
      @documents   = @project.documents.scope
    end
2012-08-01 23:19:52 +01:00
Jon Leighton
d1099540af Deprecate Relation#all.
It has been moved to active_record_deprecated_finders.

Use #to_a instead.
2012-07-27 17:55:43 +01:00
Jon Leighton
b658cf1198 Deprecate ActiveRecord::Base.scoped.
It doesn't serve much purpose now that ActiveRecord::Base.all returns a
Relation.

The code is moved to active_record_deprecated_finders.
2012-07-27 17:27:47 +01:00
Rafael Mendonça França
2d9e5a26a1 Deprecate update_column in favor of update_columns.
Closes #1190
2012-07-24 20:20:26 -03:00
Jon Leighton
0ed05b0e73 find and replace deprecated keys 2012-04-27 12:37:21 +01:00
Jon Leighton
61555a0df1 allow AssociationProxy#scoped to take options so that API is the same as Base#scoped 2012-04-27 11:52:34 +01:00
Jon Leighton
df6f971e3a %s/find(:\(first\|last\|all\), \([^()]*\))/scoped(\2).\1/gcI amongst other things 2012-04-27 11:42:50 +01:00
Jon Leighton
a2dab46cae Deprecate inferred JOINs with includes + SQL snippets.
See the CHANGELOG for details.

Fixes #950.
2012-01-16 21:32:12 +00:00
Jon Leighton
d13627d532 Revert "Deprecate implicit eager loading. Closes #950."
This reverts commit c99d507fccca2e9e4d12e49b4387e007c5481ae9.
2012-01-16 21:17:17 +00:00
Jon Leighton
c99d507fcc Deprecate implicit eager loading. Closes #950. 2011-12-29 14:27:33 +00:00
Josh Susser
c347b3c06c don't change class definition in test case 2011-11-29 09:14:21 -08:00
Josh Susser
9cdf33af0b add test for super-ing to association methods 2011-11-15 23:32:58 -08:00
Josh Susser
7cba6a3784 association methods are now generated in modules
Instead of generating association methods directly in the model
class, they are generated in an anonymous module which
is then included in the model class. There is one such module
for each association. The only subtlety is that the
generated_attributes_methods module (from ActiveModel) must
be forced to be included before association methods are created
so that attribute methods will not shadow association methods.
2011-11-15 23:32:58 -08:00
Jon Leighton
24f0a872e6 Add a proxy_association method to association proxies, which can be called by association extensions to access information about the association. This replaces proxy_owner etc with proxy_association.owner. 2011-07-27 12:36:00 +01:00
Aaron Patterson
61774e0d49 please use ruby -I lib:test path/to/test.rb, or export RUBY_OPT 2011-06-06 15:47:13 -07:00
Jon Leighton
253bb6b926 Refactor Active Record test connection setup. Please see the RUNNING_UNIT_TESTS file for details, but essentially you can now configure things in test/config.yml. You can also run tests directly via the command line, e.g. ruby path/to/test.rb (no rake needed, uses default db connection from test/config.yml). This will help us fix the CI by enabling us to isolate the different Rails versions to different databases. 2011-06-04 23:47:03 +01:00
Josh Kalderimis
542114e1d8 removed deprecated methods, and related tests, from ActiveRecord 2011-05-25 02:29:32 +02:00
Jon Leighton
0afd5850f5 Implement proxy_owner, proxy_target and proxy_reflection methods on CollectionProxy with deprecations. Fixes #1148. 2011-05-19 23:28:44 +01:00
Vishnu Atrai
33f0b6b67d minor cleaning 2011-05-10 22:51:54 +05:30
Sebastian Martinez
245542ea29 Added new #update_column method.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-27 21:47:38 -03:00
Sebastian Martinez
0e1fed537a Revert "Removed #update_attribute method. New #update_column method."
This reverts commit 45c233ef819dc7b67e259dd73f24721fec28b8c8.

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-27 18:55:30 -03:00
Sebastian Martinez
45c233ef81 Removed #update_attribute method. New #update_column method.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-03-26 12:09:04 -03:00
Jon Leighton
6975a41adf Remove test which was broken on 1.8. This test is now irrelevant since singular associations no longer return a proxy object. 2011-02-18 18:50:35 +00:00
Jon Leighton
1644663ba7 Split AssociationProxy into an Association class (and subclasses) which manages the association, and a CollectionProxy class which is *only* a proxy. Singular associations no longer have a proxy. See CHANGELOG for more. 2011-02-18 00:00:13 +00:00
Josh Kalderimis
d7db6a8873 class inheritable attributes is used no more! all internal use of class inheritable has been changed to class_attribute. class inheritable attributes has been deprecated.
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-11-20 19:40:29 +01:00
Aaron Patterson
2738ec891b removing many unused variables 2010-11-16 17:06:50 -08:00
Santiago Pastorino
b451de0d6d Deletes trailing whitespaces (over text files only find * -type f -exec sed 's/[ \t]*$//' -i {} \;) 2010-08-14 04:12:33 -03:00
Neeraj Singh
807239f5a1 Making Active Record base_test.rb thinner by moving tests
to relevant files.

Number of assertions before refactoring:
2391 tests, 7579 assertions, 0 failures, 0 errors

Number of assertions after refactoring:
2391 tests, 7579 assertions, 0 failures, 0 errors

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-03 10:45:54 +02:00
Neeraj Singh
009aa8825b Eager loading an association should not change the count of children
[#4971 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-08-02 17:12:59 +02:00
Subba Rao Pasupuleti
b0c7dee4f2 removing unused models from tests
[#5153 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-21 22:08:07 +02:00
Subba Rao Pasupuleti
96b2516c3c Strengthening the test for nested_attribute
Loading the associate target in nested_attributes
should load most recent attributes for child
records marked for destruction

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-21 14:25:34 +02:00
Ken Collins
0e9bc23c0e Fix the #using_limitable_reflections? helper to work correctly by not examining the length of an array which contains false/true, hence always passing. [#4869 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-08 22:34:34 +02:00
Xavier Noria
c8f1aac761 restricts a test to < 1.9, and rewrites it using a proper expectation
Signed-off-by: wycats <wycats@gmail.com>
2010-03-13 17:04:08 -06:00
Xavier Noria
89eae2d187 adds coverage for the issue addressed in fe43bbd
[#4166 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-03-12 13:22:47 -08:00
Will
bf6af5f719 When passing force_reload = true to an association, don't use the query cache [#1827 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
2009-12-16 10:49:53 -06:00
Emilio Tagua
046c22c8c1 Removed legacy test. 2009-07-20 16:53:48 -03:00
Michael Koziarski
cb45ee344d Remove the functionality introduce in 28d3390
There are several situations it doesn't cater for, and the inconsistency isn't worth blocking 2.2.
2008-10-10 17:04:46 +02:00
Nathaniel Talbott
9d7f186f74 Fixed an error triggered by a reload followed by a foreign key assignment.
Signed-off-by: Michael Koziarski <michael@koziarski.com>
2008-09-20 14:16:43 +02:00
Jon Leighton
fcf31cb752 Support for updating a belongs to association from the foreign key (without saving and reloading the record)
Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#142 state:committed]
2008-09-13 11:08:29 +02:00
Pratik Naik
9994f0d902 Revert "Add :accessible option to Associations for allowing mass assignments using hash. [#474 state:resolved]"
This reverts commit e0750d6a5c7f621e4ca12205137c0b135cab444a.

Conflicts:

	activerecord/CHANGELOG
	activerecord/lib/active_record/associations.rb
	activerecord/lib/active_record/associations/association_collection.rb
2008-09-10 18:50:01 +01:00
Jeremy Kemper
ab1e82b8f7 Include people and readers fixtures to fix test isolation error 2008-08-26 02:38:48 -07:00