Permalink
Browse files

Added that the 'fixture :posts' syntax can be used for has_and_belong…

…s_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
  • Loading branch information...
1 parent aef06f3 commit 9b0fd9d00d8b6e6c3b16bc513b454185fe169454 @dhh dhh committed Feb 7, 2005
Showing with 9 additions and 2 deletions.
  1. +9 −2 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 @@ def value_list
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

0 comments on commit 9b0fd9d

Please sign in to comment.