lib/ecoportal/api/common/content/double_model.rb in ecoportal-api-v2-1.1.5 vs lib/ecoportal/api/common/content/double_model.rb in ecoportal-api-v2-1.1.6

- old
+ new

@@ -26,10 +26,12 @@ def key? !!key end + # key property (and method) of this model + # @note this is auto-set when `passkey` is used def key=(value) @key = value.to_s.freeze end def new_uuid(length: 24) @@ -70,11 +72,11 @@ end # This method is essential to give stability to the model # @note `Content::CollectionModel` needs to find elements in the doc `Array`. # The only way to do it is via the access key (i.e. `id`). However, there is - # no chance you can avoid invinite loop for `get_key` without setting an + # no chance you can avoid infinite loop for `get_key` without setting an # instance variable key at the moment of the object creation, when the # `doc` is firstly received # @param method [Symbol] the method that exposes the value # as well as its `key` in the underlying `Hash` model. def passkey(method) @@ -261,10 +263,11 @@ end end inheritable_class_vars :forced_model_keys, :key + # `_key` refers to the parent's property that links to this model attr_reader :_parent, :_key, :_read_only def initialize(doc = {}, parent: self, key: nil, read_only: false) @_dim_vars = [] @_parent = parent || self @@ -319,9 +322,11 @@ return @doc if doc_var? raise UnlinkedModel.new(from: "#{self.class}#doc", key: _key) unless linked? if is_root? @doc else + # transform parent's `_key` to this object into a + # path key that can rerieve from the parents's doc _parent.doc.dig(*[_doc_key(_key)].flatten) end end # The `original_doc` holds the model as is now on server-side.