mem-store.js
function do_save(id, isnew) {
        var mement = ent.data$(true, 'string')

        if (undefined !== id) {
          mement.id = id
        }

        mement.entity$ = ent.entity$

        entmap[base] = entmap[base] || {}
        entmap[base][name] = entmap[base][name] || {}

        var prev = entmap[base][name][mement.id]
        if (isnew && prev) {
          return reply(error('entity-id-exists', { type: ent.entity$, id: id }))
        }

        var shouldMerge = true
        if (options.merge !== false && ent.merge$ === false) {
          shouldMerge = false
        }
        if (options.merge === false && ent.merge$ !== true) {
          shouldMerge = false
        }

        mement = _.cloneDeep(mement)
        if (shouldMerge) {
          mement = _.assign(prev || {}, mement)
        }
        prev = entmap[base][name][mement.id] = mement

        seneca.log.debug(function() {
          return [
            'save/' + (create ? 'insert' : 'update'),
            ent.canon$({ string: 1 }),
            mement,
            desc
          ]
        })

        reply(null, ent.make$(prev))
      }
function do_save(id, isnew) {
        var mement = ent.data$(true, 'string')

        if (undefined !== id) {
          mement.id = id
        }

        mement.entity$ = ent.entity$

        entmap[base] = entmap[base] || {}
        entmap[base][name] = entmap[base][name] || {}

        var prev = entmap[base][name][mement.id]
        if (isnew && prev) {
          return reply(error('entity-id-exists', { type: ent.entity$, id: id }))
        }

        var shouldMerge = true
        if (options.merge !== false && ent.merge$ === false) {
          shouldMerge = false
        }
        if (options.merge === false && ent.merge$ !== true) {
          shouldMerge = false
        }

        mement = _.cloneDeep(mement)
        if (shouldMerge) {
          mement = _.assign(prev || {}, mement)
        }
        prev = entmap[base][name][mement.id] = mement

        seneca.log.debug(function() {
          return [
            'save/' + (create ? 'insert' : 'update'),
            ent.canon$({ string: 1 }),
            mement,
            desc
          ]
        })

        reply(null, ent.make$(prev))
      }
function do_save ( id , isnew ) { var mement = ent . data$ ( true , 'string' ) if ( undefined !== id ) { mement . id = id } mement . entity$ = ent . entity$ entmap [ base ] = entmap [ base ] || { } entmap [ base ] [ name ] = entmap [ base ] [ name ] || { } var prev = entmap [ base ] [ name ] [ mement . id ] if ( isnew && prev ) { return reply ( error ( 'entity-id-exists' , { type : ent . entity$ , id : id } ) ) } var shouldMerge = true if ( options . merge !== false && ent . merge$ === false ) { shouldMerge = false } if ( options . merge === false && ent . merge$ !== true ) { shouldMerge = false } mement = _ . cloneDeep ( mement ) if ( shouldMerge ) { mement = _ . assign ( prev || { } , mement ) } prev = entmap [ base ] [ name ] [ mement . id ] = mement seneca . log . debug ( function ( ) { return [ 'save/' + ( create ? 'insert' : 'update' ) , ent . canon$ ( { string : 1 } ) , mement , desc ] } ) reply ( null , ent . make$ ( prev ) ) }
The actual save logic for saving or creating and then saving the entity.
The actual save logic for saving or creating and then saving the entity .