Skip to content

Commit

Permalink
set a constant for the "anonymous" habtm model fixes #15022
Browse files Browse the repository at this point in the history
I wanted the middle model to be anonymous, but we have to give it a name
for marshal support. :'(
  • Loading branch information
tenderlove committed May 8, 2014
1 parent 83e0544 commit 6ffce17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activerecord/lib/active_record/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,11 @@ def has_and_belongs_to_many(name, scope = nil, options = {}, &extension)

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def setup_data_for_habtm_case
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

Expand Down

0 comments on commit 6ffce17

Please sign in to comment.