mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Move polymorphic to initialize + reader
This commit is contained in:
parent
36feb5d44f
commit
0b6326eb35
@ -80,6 +80,11 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
class HasOne < Base #:nodoc:
|
class HasOne < Base #:nodoc:
|
||||||
|
def initialize(name, options={}, serializer_options={})
|
||||||
|
super
|
||||||
|
@polymorphic = options[:polymorphic]
|
||||||
|
end
|
||||||
|
|
||||||
def root
|
def root
|
||||||
if root = options[:root]
|
if root = options[:root]
|
||||||
root
|
root
|
||||||
@ -132,14 +137,13 @@ module ActiveModel
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
attr_reader :polymorphic
|
||||||
|
alias polymorphic? polymorphic
|
||||||
|
|
||||||
def use_id_key?
|
def use_id_key?
|
||||||
embed_ids? && !polymorphic?
|
embed_ids? && !polymorphic?
|
||||||
end
|
end
|
||||||
|
|
||||||
def polymorphic?
|
|
||||||
options[:polymorphic]
|
|
||||||
end
|
|
||||||
|
|
||||||
def polymorphic_key
|
def polymorphic_key
|
||||||
object.class.to_s.demodulize.underscore.to_sym
|
object.class.to_s.demodulize.underscore.to_sym
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user