diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-02-24 16:24:38 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-02-24 16:24:38 -0800 |
commit | f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4 (patch) | |
tree | 6d34ad08f99ec8dc0192a7b1474342634616f41d | |
parent | f4f94081dd1a3e9ff99e17ae88b7d91fcdbb19fc (diff) | |
parent | 8e16a00de4f77f15e405d083d535b92a23779d9d (diff) | |
download | rails-f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4.tar.gz rails-f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4.tar.bz2 rails-f4bee7ecbfd664a9268ae8a6cdf3deabf0ed74e4.zip |
Merge pull request #17426 from jpcody/fixture_associations_fix
Rely on through table name in has_many fixtures
-rw-r--r-- | activerecord/lib/active_record/fixtures.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/fixtures_test.rb | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 739be524da..75b0e1e08d 100644 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -708,6 +708,10 @@ module ActiveRecord def lhs_key @association.through_reflection.foreign_key end + + def join_table + @association.through_reflection.table_name + end end private diff --git a/activerecord/test/cases/fixtures_test.rb b/activerecord/test/cases/fixtures_test.rb index f41245dfd2..7ef2ebc998 100644 --- a/activerecord/test/cases/fixtures_test.rb +++ b/activerecord/test/cases/fixtures_test.rb @@ -273,7 +273,7 @@ class HasManyThroughFixture < ActiveSupport::TestCase Class.new(ActiveRecord::Base) { define_singleton_method(:name) { name } } end - def test_has_many_through + def test_has_many_through_with_default_table_name pt = make_model "ParrotTreasure" parrot = make_model "Parrot" treasure = make_model "Treasure" @@ -292,6 +292,24 @@ class HasManyThroughFixture < ActiveSupport::TestCase assert_equal load_has_and_belongs_to_many['parrots_treasures'], rows['parrots_treasures'] end + def test_has_many_through_with_renamed_table + pt = make_model "ParrotTreasure" + parrot = make_model "Parrot" + treasure = make_model "Treasure" + + pt.belongs_to :parrot, :class => parrot + pt.belongs_to :treasure, :class => treasure + + parrot.has_many :parrot_treasures, :class => pt + parrot.has_many :treasures, :through => :parrot_treasures + + parrots = File.join FIXTURES_ROOT, 'parrots' + + fs = ActiveRecord::FixtureSet.new parrot.connection, "parrots", parrot, parrots + rows = fs.table_rows + assert_equal load_has_and_belongs_to_many['parrots_treasures'], rows['parrot_treasures'] + end + def load_has_and_belongs_to_many parrot = make_model "Parrot" parrot.has_and_belongs_to_many :treasures |