Commit Graph

99 Commits

Author SHA1 Message Date
Xavier Noria
d22e522179 modernizes hash syntax in activerecord 2016-08-06 19:37:57 +02:00
Xavier Noria
9617db2078 applies new string literal convention in activerecord/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:26:53 +02:00
Rafael França
b37bd3d52f Merge pull request #25941 from kamipo/finder_methods_uses_load_target
`FinderMethods` uses `records` (`load_target`) when `loaded?` is true
2016-07-28 10:39:04 -03:00
Rafael França
519801db08 Merge pull request #25940 from kamipo/fix_collection_proxy_load
Fix to `CollectionProxy#load` does `load_target`
2016-07-28 10:36:50 -03:00
Ryuta Kamizono
fe48c97e26 FinderMethods uses records (load_target) when loaded? is true 2016-07-28 13:54:46 +09:00
Ryuta Kamizono
ceee776b5d Fix to CollectionProxy#load does load_target 2016-07-25 00:00:38 +09:00
Ryuta Kamizono
beb6b7add7 load_target is a public method
`send` is unnecessary.
2016-07-23 17:14:41 +09:00
akihiro17
715e845fa2 Remove unnecessary require in associations_test.rb 2015-09-03 04:27:07 +09:00
Ronak Jangir
592ba58208 Removed duplicate require ‘models/computer’ 2015-08-26 21:53:03 +05:30
Prem Sichanugrist
b5b8979621 Silence deprecation warning from force reload
We deprecate the support for passing an argument to force reload in
6eae366d0d2e5d5211eeaf955f56bd1dc6836758. That led to several
deprecation warning when running Active Record test suite.

This commit silence the warnings by properly calling `#reload` on the
association proxy or on the association object instead. However, there
are several places that `ActiveSupport::Deprecation.silence` are used as
those tests actually tests the force reload functionality and will be
removed once `master` is targeted next minor release (5.1).
2015-07-16 16:06:26 -04:00
Rafael Mendonça França
17e0878005 Do not test, document or use a private API method
These methods are nodoc so we should not document them.
2015-02-20 17:50:20 -02:00
Rafael Mendonça França
37bef5827f Merge pull request #16989 from Empact/reload-cache-clear
Isolate access to @associations_cache and @aggregations_cache to the Associations and Aggregations modules, respectively.
2015-02-20 17:45:10 -02:00
Sean Griffin
d26dd00854 WhereClause#predicates does not need to be public
The only place it was accessed was in tests. Many of them have another
way that they can test their behavior, that doesn't involve reaching
into internals as far as they did. `AssociationScopeTest` is testing a
situation where the where clause would have one bind param per
predicate, so it can just ignore the predicates entirely. The where
chain test was primarly duplicating the logic tested on `WhereClause`
directly, so I instead just make sure it calls the appropriate method
which is fully tested in isolation.
2015-01-27 10:30:38 -07:00
Sean Griffin
6a7ac40dab Go through normal where logic in AssociationScope
This removes the need to duplicate much of the logic in `WhereClause`
and `PredicateBuilder`, simplifies the code, removes the need for the
connection adapter to be continuously passed around, and removes one
place that cares about the internal representation of `bind_values`

Part of the larger refactoring to change how binds are represented
internally

[Sean Griffin & anthonynavarre]
2015-01-26 15:49:29 -07:00
Sean Griffin
17b1b5d773 Remove all references to where_values in tests 2015-01-25 17:50:19 -07:00
Sean Griffin
fb14aa0c1b Ensure first! and friends work on loaded associations
Fixes #18237
2014-12-29 11:56:37 -07:00
Erik Michaels-Ober
d1374f99bf Pass symbol as an argument instead of a block 2014-11-29 11:53:24 +01:00
Arun Agrawal
9ae210ba09 Build fix when running in isolation
`Computer` class needs to be require

See #17217 for more details
2014-11-14 10:24:11 +01:00
Ben Woosley
9d569585a2 Isolate access to @associations_cache and @aggregations cache to the Associations and Aggregations modules, respectively.
This includes replacing the `association_cache` accessor with a more
limited `association_cached?` accessor and making `clear_association_cache`
and `clear_aggregation_cache` private.
2014-09-28 16:17:06 -07:00
Yves Senn
d5580b91b6 Allow included modules to override association methods.
Closes #16684.

This is achieved by always generating `GeneratedAssociationMethods` when
`ActiveRecord::Base` is subclassed. When some of the included modules
of `ActiveRecord::Base` were reordered this behavior was broken as
`Core#initialize_generated_modules` was no longer called. Meaning that
the module was generated on first access.
2014-09-09 10:00:30 +02:00
Aaron Patterson
2e6625fb77 always reorder bind parameters. fixes #15920 2014-09-04 14:40:19 -07:00
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