lib/wcc/contentful/model_methods.rb in wcc-contentful-1.3.2 vs lib/wcc/contentful/model_methods.rb in wcc-contentful-1.4.0.rc1
- old
+ new
@@ -39,11 +39,11 @@
typedef = self.class.content_type_definition
links = fields.select { |f| %i[Asset Link].include?(typedef.fields[f].type) }
store = context[:preview] ? self.class.services.preview_store : self.class.services.store
raw_link_ids =
- links.map { |field_name| raw.dig('fields', field_name, sys.locale) }
+ links.map { |field_name| raw.dig('fields', field_name) }
.flat_map do |raw_value|
_try_map(raw_value) { |v| v.dig('sys', 'id') if v.dig('sys', 'type') == 'Link' }
end
raw_link_ids = raw_link_ids.compact
backlinked_ids = (context[:backlinks]&.map { |m| m.id } || [])
@@ -60,11 +60,11 @@
}))
end
raise WCC::Contentful::ResolveError, "Cannot find #{self.class.content_type} with ID #{id}" unless raw
@raw = raw.freeze
- links.each { |f| instance_variable_set("@#{f}", raw.dig('fields', f, sys.locale)) }
+ links.each { |f| instance_variable_set("@#{f}", raw.dig('fields', f)) }
end
links.each { |f| _resolve_field(f, depth, context, options) }
self
end
@@ -83,13 +83,11 @@
# Turns the current model into a hash representation as though it had been retrieved from
# the Contentful API.
#
# This differs from `#raw` in that it recursively includes the `#to_h`
- # of resolved links. It also sets the fields to the value for the entry's `#sys.locale`,
- # as though the entry had been retrieved from the API with `locale={#sys.locale}` rather
- # than `locale=*`.
+ # of resolved links.
def to_h(stack = nil)
raise WCC::Contentful::CircularReferenceError.new(stack, id) if stack&.include?(id)
stack = [*stack, id]
typedef = self.class.content_type_definition
@@ -120,10 +118,10 @@
h[name] = val
end
{
- 'sys' => { 'locale' => @sys.locale }.merge!(@raw['sys']),
+ 'sys' => @raw['sys'].dup,
'fields' => fields
}
end
delegate :to_json, to: :to_h