@_CreateUnwrapped = @_WrapParams do
* \Object : optional: true
* \Array : optional: true
* \Object : optional: true
* \Function
* \Number : optional: true
(arg, args, config, done, _depth = @config?.maxDepth) ->
if args?
@debug-resource.Log "Creating from array: #{args.length} entries"
@_HandleArrayArg arg || args || {}, (blob, done) ~>
async.mapSeries obj-to-pairs(blob), (pair, done) ~>
if pair.0 in (@_schema.assocs |> map (.foreign)) and pair.1?._promise
pair.1.Then -> done null [pair.0, it.id]
pair.1.Catch done
else
done null, pair
, (err, results) ~>
return done err if err?
blob = pairs-to-obj results
@debug-resource.Log "Creating #{JSON.stringify blob}"
@resource._Deserialize blob, (err, instance) ~>
| err? => done err
| _ =>
c = {}
if config?.db?
@_table.AddDriver config
c = config
else
c = @config
instance._SaveUnwrapped c, (err, instance) ~>
| err? => done err
| _ =>
if instance._schema.assocs.length
@_schema.FetchAssoc instance, (err, blob) ~>
| err? => done err
| _ =>
instance import blob
@debug-resource.Log "Created {id: #{instance.id}}"
done null instance
, _depth
else
@debug-resource.Log "Created {id: #{instance.id}}"
done null instance
, _depth
, done