diff options
author | Tarmo Tänav <tarmo@itech.ee> | 2008-08-23 21:54:43 +0300 |
---|---|---|
committer | Tarmo Tänav <tarmo@itech.ee> | 2008-08-23 21:54:43 +0300 |
commit | b1f3c6e6ec08a40fc7153ee3ba78d51b466a58e6 (patch) | |
tree | a1ec39f011ff12c0f052c81c6927c8d30cf8e8eb /railties/lib | |
parent | 9223a919111867e6b47b2627c30d8eb21e8ac7d9 (diff) | |
download | rails-b1f3c6e6ec08a40fc7153ee3ba78d51b466a58e6.tar.gz rails-b1f3c6e6ec08a40fc7153ee3ba78d51b466a58e6.tar.bz2 rails-b1f3c6e6ec08a40fc7153ee3ba78d51b466a58e6.zip |
Generate belongs_to association when generating a model
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails_generator/generated_attribute.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails_generator/generators/components/model/templates/model.rb | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/railties/lib/rails_generator/generated_attribute.rb b/railties/lib/rails_generator/generated_attribute.rb index 25af3931de..a3d4a01142 100644 --- a/railties/lib/rails_generator/generated_attribute.rb +++ b/railties/lib/rails_generator/generated_attribute.rb @@ -37,6 +37,10 @@ module Rails "" end end + + def reference? + [ :references, :belongs_to ].include?(self.type) + end end end end diff --git a/railties/lib/rails_generator/generators/components/model/templates/model.rb b/railties/lib/rails_generator/generators/components/model/templates/model.rb index 8bf93b9e8b..6fcf393bdf 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/model.rb +++ b/railties/lib/rails_generator/generators/components/model/templates/model.rb @@ -1,5 +1,5 @@ class <%= class_name %> < ActiveRecord::Base -<% attributes.select { |a| a.type.to_s == 'references' }.each do |attribute| -%> +<% attributes.select(&:reference?).each do |attribute| -%> belongs_to :<%= attribute.name %> <% end -%> end |