Commit Graph

76 Commits

Author SHA1 Message Date
Neeraj Singh
cd9592959f scope_chain should not be mutated for other reflections
Currently `scope_chain` uses same array for building different
`scope_chain` for different associations. During processing
these arrays are sometimes mutated and because of in-place
mutation the changed `scope_chain` impacts other reflections.

Fix is to dup the value before adding to the `scope_chain`.

Fixes #3882.
2013-10-14 11:59:59 -04:00
Aaron Patterson
b8aebb0261 acually get the actual source reflection 😢🔫 2013-07-23 17:02:14 -07:00
Neeraj Singh
1a560e6160 Removing not useful test related to reflect_on_all_associations
The comment in the test pretty much summarizes the issue.
`FIXME these assertions bust a lot`

Adding any type of association in class `Firm` will break this test.

I removed some deprecated stuff and this test failed.

I do not think this test provides any useful value. First of all who
counted last that 39 is the right number of associations.

Secondly there are a large number of tests which depend on reflection
returning right information about associations. Those tests will start
failing if there is a bug in the code.
2013-07-02 12:14:16 +05:30
Takehiro Adachi
2dbb346ffe Fix tests which started to fail due to commit 0123c39f41e2062311b2197e6e230ef8ad67e20e
Due to commit 0123c39f41e2062311b2197e6e230ef8ad67e20e, column
topic.unique_replies_count has been added, and these test started to
fail since the tests depends on the topic tables column info.
2013-05-18 18:22:21 +09:00
Yves Senn
626f7df626 remove duplicated require statements in AR test cases 2012-10-09 21:33:54 +02:00
Jon Leighton
7f3b475608 Revert "Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql."
This reverts commit 3803fcce26b837c0117f7d278b83c366dc4ed370.

Conflicts:
	activerecord/CHANGELOG.md

It will be deprecated only in 4.0, and removed properly in 4.1.
2012-08-01 19:46:31 +01:00
Rafael Mendonça França
f4d818d51e Revert "Removing composed_of from ActiveRecord."
This reverts commit 14fc8b34521f8354a17e50cd11fa3f809e423592.

Reason: we need to discuss a better path from this removal.

Conflicts:
	activerecord/lib/active_record/reflection.rb
	activerecord/test/cases/base_test.rb
	activerecord/test/models/developer.rb
2012-07-27 19:25:14 -03:00
Jon Leighton
3803fcce26 Remove :finder_sql, :counter_sql, :insert_sql, :delete_sql. 2012-07-20 19:00:46 +01:00
Jon Leighton
65843e1acc Represent association scope options as AR::Relations insternally. 2012-07-13 16:23:06 +01:00
Jon Leighton
5a54bffe37 Allow associations to take a lambda which builds the scope 2012-07-13 11:55:48 +01:00
Andrew White
5befebabc3 Add test cases for 46492949b8c09f99db78b9f7a02d039e7bc6a702 2012-06-23 10:43:25 +01:00
Steve Klabnik
14fc8b3452 Removing composed_of from ActiveRecord.
This feature adds a lot of complication to ActiveRecord for dubious
value. Let's talk about what it does currently:

class Customer < ActiveRecord::Base
  composed_of :balance, :class_name => "Money", :mapping => %w(balance amount)
end

Instead, you can do something like this:

    def balance
      @balance ||= Money.new(value, currency)
    end

    def balance=(balance)
      self[:value] = balance.value
      self[:currency] = balance.currency
      @balance = balance
    end

Since that's fairly easy code to write, and doesn't need anything
extra from the framework, if you use composed_of today, you'll
have to add accessors/mutators like that.

Closes #1436
Closes #2084
Closes #3807
2012-06-18 14:53:03 -04:00
Jon Leighton
75f03eca75 remove calls to find(:first), find(:last) and find(:all) 2012-04-26 18:32:55 +01:00
gregolsen
58cd0085a9 reflection test fixed 2012-01-31 15:57:39 +02: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
Alvaro Bautista
30ce084bbf serialize fails on subclass 2011-12-23 18:19:25 +00:00
Arun Agrawal
6da558660c Fix test as one more has_many added 2011-11-04 19:30:59 +05:30
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
Jon Leighton
d486103570 Fix #3271.
Building the conditions of a nested through association could
potentially modify the conditions of the through and/or source
association.

This is a Bad Thing.
2011-11-03 15:12:08 +00:00
Jon Leighton
2e9e647fee Raise an exception on unknown primary key inside AssociationReflection.
An association between two models cannot be made if a relevant key is
unknown, so fail fast rather than generating invalid SQL. Fixes #3207.
2011-10-05 20:21:21 +01:00
Jon Leighton
adb8ac153f Don't call self.class unless necessary. Closes #3171. 2011-09-29 18:00:30 +01:00
Jon Leighton
3b87c38d02 Fix belongs_to polymorphic with custom primary key on target.
Closes #3104.
2011-09-26 15:42:34 +01:00
Aaron Patterson
f261ef42cc cache the plural name on the reflection so we do not pay pluralize costs on joins 2011-06-30 15:31:22 -07: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
d7a910e31e Fix problem with loading polymorphic associations which have been defined in an abstract superclass. Fixes #552. 2011-05-22 21:25:02 +01:00
Jon Leighton
9abc94c445 oracle, y u defy me 2011-03-16 18:54:34 +00:00
Jon Leighton
39a6f4f25d Simplify implementation of ThroughReflection#chain 2011-03-11 00:51:57 +00:00
Jon Leighton
2d3d9e3531 Rename Reflection#through_reflection_chain and #through_options to Reflection#chain and Reflection#options as they now no longer relate solely to through associations. 2011-03-10 19:28:26 +00:00
Jon Leighton
7fddb94262 Push source_type and polymorphic conditions out of ThroughAssociation and JoinDependency::JoinAssociation and into the reflection instead. 2011-03-05 22:07:30 +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
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
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
c47f802d0e Have a proper AssociationReflection#foreign_type method rather than using options[:foreign_type] 2011-01-03 16:24:31 -08:00
Jon Leighton
1267598881 Rename AssociationReflection#primary_key_name to foreign_key, since the options key which it relates to is :foreign_key 2010-12-31 20:00:45 +00:00
Jon Leighton
2d9626fc74 Improved strategy for updating a belongs_to association when the foreign key changes. Rather than resetting each affected association when the foreign key changes, we should lazily check for 'staleness' (where fk does not match target id) when the association is accessed. 2010-12-23 15:19:18 -08:00
Jon Leighton
b8153fd5a1 Fix problem where wrong keys are used in JoinAssociation when an association goes :through a belongs_to [#2801 state:resolved] 2010-12-20 13:56:04 -08:00
Jon Leighton
14b880fd03 Fix various issues with the :primary_key option in :through associations [#2421 state:resolved] 2010-12-15 17:50:14 -08:00
Jon Leighton
9a98c766e0 Merge branch 'master' into nested_has_many_through
Conflicts:
	activerecord/CHANGELOG
	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_through_association.rb
2010-12-12 09:55:32 +00:00
Santiago Pastorino
42c51b8527 Doesn't need to sort, lets users of attribute_names sort them if they want 2010-12-02 20:28:24 -02:00
Jon Leighton
e05162cffa Merge branch 'master' into nested_has_many_through
Conflicts:
	activerecord/lib/active_record/associations.rb
2010-11-08 11:02:26 +00:00
Pratik Naik
c5c2e4fefd Add timestamps to Topic 2010-11-02 01:24:31 +00:00
Jon Leighton
9a1a32ac2b Fix naughty trailing whitespace 2010-10-31 11:21:28 +00:00
Jon Leighton
82b889f7d3 Add explicit tests for the nested through association changes in reflection.rb 2010-10-19 17:22:42 +01: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
a3ce6fcc56 adding column named 'group' to ensure that nothing breaks given that 'group' is sql reserved word
[#4945 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-06-23 17:46:37 +02:00
Aaron Patterson
dcf1441c0f removing dead code from activerecord tests. [#4187 state:resolved]
Signed-off-by: wycats <wycats@gmail.com>
2010-03-15 18:36:08 -07:00
Eloy Duran
7f775ef1a9 Renamed AssociationReflection #collection_association? to #collection?. 2010-01-08 21:47:17 +01:00
Eloy Duran
b6264c43f4 Moved the validation logic to the association reflection and refactored autosave_association.rb a bit. 2010-01-07 13:19:48 +01:00