 
   get: (key) ->
     if @getRelationships()?[key]?
-      return e "Not inserted object should not be able to get relationship, please fix this" unless @isInserted()
       relationship = @getRelationships()[key]
-      resolveRelationship(@, relationship)
+      result = resolveRelationship(@, relationship)
+      result = @_pendingRelationships?[key] unless result?
+      result
     else
       @_object?[key]
 

          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
        else
          e "Bad relationship #{relationship.name} <-> #{relationship.inverse}. You must absolutely check for errors for classes #{ClassName} and #{relationship.Class}"


  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

