diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-07 14:10:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-07 14:10:44 +0000 |
commit | 9b0fd9d00d8b6e6c3b16bc513b454185fe169454 (patch) | |
tree | 123f84235d04200ef53faafb2523765794c164be /activerecord/lib | |
parent | aef06f3b6048c4ba712ec79c0f47a2a59af5dec8 (diff) | |
download | rails-9b0fd9d00d8b6e6c3b16bc513b454185fe169454.tar.gz rails-9b0fd9d00d8b6e6c3b16bc513b454185fe169454.tar.bz2 rails-9b0fd9d00d8b6e6c3b16bc513b454185fe169454.zip |
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
Diffstat (limited to 'activerecord/lib')
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 11 |
1 files changed, 9 insertions, 2 deletions
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 |