Added that the 'fixture :posts' syntax can be used for has_and_belongs_to_many...

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
上级 aef06f3b
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册