aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2016-01-31 23:07:27 +0900
committeryui-knk <spiketeika@gmail.com>2016-02-01 08:02:33 +0900
commit615dcadba0c18e332a497c515b66215c446dfe1d (patch)
treed9f9c01a9b81191563845541d8c870399ef23bd6 /activerecord
parent5c9cccaf25888836aacbca24dbbe8e94d0d61eac (diff)
downloadrails-615dcadba0c18e332a497c515b66215c446dfe1d.tar.gz
rails-615dcadba0c18e332a497c515b66215c446dfe1d.tar.bz2
rails-615dcadba0c18e332a497c515b66215c446dfe1d.zip
Remove `case macro` from `calculate_constructable`
Rails has abstract Reflection classes (`MacroReflection`, `AssociationReflection` etc.) and concrete Reflection classes (e.g. `HasManyReflection`, `HasOneReflection` etc.). In many case `calculate_constructable` returns `true`, so change `calculate_constructable` to always return `true` and override this method if necessary.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/reflection.rb21
1 files changed, 13 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index cbb5b99a05..823ca1f54f 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -501,14 +501,7 @@ module ActiveRecord
private
def calculate_constructable(macro, options)
- case macro
- when :belongs_to
- !polymorphic?
- when :has_one
- !options[:through]
- else
- true
- end
+ true
end
# Attempts to find the inverse association name automatically.
@@ -634,6 +627,12 @@ module ActiveRecord
Associations::HasOneAssociation
end
end
+
+ private
+
+ def calculate_constructable(macro, options)
+ !options[:through]
+ end
end
class BelongsToReflection < AssociationReflection # :nodoc:
@@ -661,6 +660,12 @@ module ActiveRecord
def join_id_for(owner) # :nodoc:
owner[foreign_key]
end
+
+ private
+
+ def calculate_constructable(macro, options)
+ !polymorphic?
+ end
end
class HasAndBelongsToManyReflection < AssociationReflection # :nodoc: