From 9b0fd9d00d8b6e6c3b16bc513b454185fe169454 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 7 Feb 2005 14:10:44 +0000 Subject: Added that the 'fixture :posts' syntax can be used for has_and_belongs_to_many fixtures where a model doesn't exist #572 [bitsweat] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@524 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/fixtures.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/fixtures.rb') diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 5299fe0a40..2e356cd8fb 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -146,7 +146,11 @@ class Fixtures < Hash def self.instantiate_fixtures(object, fixtures_directory, *table_names) [ create_fixtures(fixtures_directory, *table_names) ].flatten.each_with_index do |fixtures, idx| object.instance_variable_set "@#{table_names[idx]}", fixtures - fixtures.each { |name, fixture| object.instance_variable_set "@#{name}", fixture.find } + fixtures.each do |name, fixture| + if model = fixture.find + object.instance_variable_set "@#{name}", model + end + end end end @@ -294,7 +298,10 @@ class Fixture #:nodoc: end def find - Object.const_get(@class_name).find(self[Object.const_get(@class_name).primary_key]) + if Object.const_defined?(@class_name) + klass = Object.const_get(@class_name) + klass.find(self[klass.primary_key]) + end end private -- cgit v1.2.3