From 6ffce1791ab989afb0f3bc1dd579804fc9a5c756 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 8 May 2014 09:51:48 -0700 Subject: set a constant for the "anonymous" habtm model fixes #15022 I wanted the middle model to be anonymous, but we have to give it a name for marshal support. :'( --- activerecord/lib/active_record/associations.rb | 5 +++++ .../cases/associations/has_and_belongs_to_many_associations_test.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index ac1479ad8f..d66a79a137 100644 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1576,6 +1576,11 @@ module ActiveRecord join_model = builder.through_model + # FIXME: we should move this to the internal constants. Also people + # should never directly access this constant so I'm not happy about + # setting it. + const_set join_model.name, join_model + middle_reflection = builder.middle_reflection join_model Builder::HasMany.define_callbacks self, middle_reflection diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index c166fe87e8..cfdfff6af9 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -83,6 +83,12 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase country.treaties << treaty end + def test_marshal_dump + post = posts :welcome + preloaded = Post.includes(:categories).find post.id + assert_equal preloaded, Marshal.load(Marshal.dump(preloaded)) + end + def test_should_property_quote_string_primary_keys setup_data_for_habtm_case -- cgit v1.2.3