           continue
         else if not InverseClass._relationships?[relationship.inverse]
           InverseClass._relationships ?= {}
-          InverseClass._relationships[relationship.inverse] = name: relationship.inverse, type: relationship.inverseType, inverse:relationship.name, Class: ClassName, inverseType: relationship.type
+          InverseClass._relationships[relationship.inverse] = name: relationship.inverse, type: relationship.inverseType, inverse:relationship.name, Class: ClassName, inverseType: relationship.type, onDelete: 'nullify'
         else
           e "Bad relationship #{relationship.name} <-> #{relationship.inverse}. You must absolutely check for errors for classes #{ClassName} and #{relationship.Class}"
 

  set: (key, value) ->
    @_object ?= {}
    if @getRelationships()?[key]?
      return e "Not inserted object should not be able to set up relationship, please fix this" unless @isInserted()
      relationship = @getRelationships()[key]

    else
      @_object[key] = value
    @_needsUpdate = yes

  remove: (key, value) ->

  add: (key, value) ->

  save: () ->
    if @isInserted() and @hasChange()
      @_collection.update @_object
    else
      @_object ?= {}
      @_collection.insert()
      @_needsUpdate = no

  delete: () ->
    unless @_deleted
      @_deleted = true
      @_collection.remove @_object

  isInserted: () -> if @_object?.meta? then yes else no

  isDeleted: () -> @_deleted

  hasChange: () -> @_needsUpdate

  getRelationships: () -> @constructor._relationships

  _getModelValue: (relationship, value) ->


  _commitPendingRelationship: () ->
    for relationshipName, pending of @_pendingRelationships
      relationship = @getRelationships()[relationshipName]
      continue unless relationship?
      switch relationship.type
        when 'many_one'
          for v in pending.value
            value = @_getModelValue(relationship, v)
        when 'one_many'
          value = @_getModelValue(relationship, pending.value)
        when 'one_one'
          value = @_getModelValue(relationship, pending.value)
        when 'many_many' then throw 'many:many relationships are not implemented yet'
    @_pendingRelationships = null

  @create: (base, context = ledger.db.contexts.main) -> new @ context, base

