aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails_generator/generated_attribute.rb4
-rw-r--r--railties/lib/rails_generator/generators/components/model/templates/model.rb3
2 files changed, 7 insertions, 0 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 8d4c89e912..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,2 +1,5 @@
class <%= class_name %> < ActiveRecord::Base
+<% attributes.select(&:reference?).each do |attribute| -%>
+ belongs_to :<%= attribute.name %>
+<% end -%>
end