anchor.diff:              end
           end
       ).
  -add_links(#model_config{bucket = _Bucket} = ModelConfig, Key, Links) when is_list(Links) ->
  -    case get(ModelConfig, links_doc_key(Key)) of
  -        {ok, #document{value = #links{link_map = LinkMap}}} ->
  -            add_links4(ModelConfig, Key, Links, LinkMap);
  -        {error, {not_found, _}} ->
  -            add_links4(ModelConfig, Key, Links, #{});
  -        {error, Reason} ->
  -            {error, Reason}
  -    end.
   
   -spec add_links4(model_behaviour:model_config(), datastore:ext_key(), [datastore:normalized_link_spec()], InternalCtx :: term()) ->
       ok | datastore:generic_error().
  
positive.code: %%--------------------------------------------------------------------
  -spec delete_links(model_behaviour:model_config(), datastore:ext_key(), [datastore:link_name()] | all) ->
      ok | datastore:generic_error().
  delete_links(#model_config{bucket = Bucket} = ModelConfig, Key, all) ->
      delete(ModelConfig, links_doc_key(Bucket, Key), ?PRED_ALWAYS);
  delete_links(#model_config{name = ModelName, bucket = Bucket} = ModelConfig, Key, Links) ->
      datastore:run_synchronized(ModelName, to_binary({?MODULE, Bucket, Key}),
          fun() ->
              case get(ModelConfig, links_doc_key(Bucket, Key)) of
                  {ok, #document{value = #links{link_map = LinkMap}}} ->
                      delete_links4(ModelConfig, Key, Links, LinkMap);
                  {error, {not_found, _}} ->
  
negative.code: add_links(#model_config{name = ModelName, bucket = Bucket} = ModelConfig, Key, Links) when is_list(Links) ->
      datastore:run_synchronized(ModelName, to_binary({?MODULE, Bucket, Key}),
          fun() ->
              case get(ModelConfig, links_doc_key(Key)) of
                  {ok, #document{value = #links{link_map = LinkMap}}} ->
                      add_links4(ModelConfig, Key, Links, LinkMap);
                  {error, {not_found, _}} ->
  