mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Make schema not crash on computed attributes
We do not know the type for computed attributes, so we pick nil. Perhaps at some point we might add a :type option for attributes (or not), but in any case it's important to not crash when there are computed attributes.
This commit is contained in:
@@ -169,9 +169,15 @@ module ActiveModel
|
||||
klass = model_class
|
||||
columns = klass.columns_hash
|
||||
|
||||
attrs = _attributes.inject({}) do |hash, (name,key)|
|
||||
column = columns[name.to_s]
|
||||
hash.merge key => column.type
|
||||
attrs = {}
|
||||
_attributes.each do |name, key|
|
||||
if column = columns[name.to_s]
|
||||
attrs[key] = column.type
|
||||
else
|
||||
# Computed attribute (method on serializer or model). We cannot
|
||||
# infer the type, so we put nil.
|
||||
attrs[key] = nil
|
||||
end
|
||||
end
|
||||
|
||||
associations = _associations.inject({}) do |hash, (attr,association_class)|
|
||||
|
||||
Reference in New Issue
Block a user