提交 9223a919 编写于 作者: T Tarmo Tänav

Generate belongs_to associations automatically for 'references' types [#640 state:resolved]

上级 a652c300
class <%= class_name %> < ActiveRecord::Base
<% attributes.select { |a| a.type.to_s == 'references' }.each do |attribute| -%>
belongs_to :<%= attribute.name %>
<% end -%>
end
......@@ -29,4 +29,12 @@ def test_model_with_attributes_generates_resources_with_attributes
assert_generated_column t, :created_at, :timestamp
end
end
def test_model_with_reference_attributes_generates_belongs_to_associations
run_generator('model', %w(Product name:string supplier:references))
assert_generated_model_for :product do |body|
assert body =~ /^\s+belongs_to :supplier/, "#{body.inspect} should contain 'belongs_to :supplier'"
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册