import { InternalSession } from "./session" ; import { EntityMapping } from "./mapping/entityMapping" ; import { ResultCallback } from "./core/callback" ; import { PersistenceError } from "./persistenceError" ; hidden export class Reference { /**
     * The id of the reference as a string.
     */ id : string ; constructor ( public mapping , private _id ) { if ( _id != null ) { this . id = _id . toString ( ) ; } } fetch ( session , callback ) { if ( ! this . mapping ) { callback ( new PersistenceError ( "Object type is not mapped as an entity." ) ) ; return ; } if ( this . _id == null ) { callback ( new PersistenceError ( "Missing or invalid identifier." ) ) ; return ; } session . getPersister ( this . mapping ) . findOneById ( this . _id , callback ) ; } param other equals ( other ) { return Reference . areEqual ( this , other ) ; } param value1 param value2 static areEqual ( value1 , value2 ) { if ( value1 == value2 ) return true ; if ( value1 == null || value2 == null ) return false ; if ( Reference . isReference ( value1 ) ) { var mapping1 = ( < Reference > value1 ) . mapping ; var id1 = ( < Reference > value1 ) . _id ; } else { var id1 = value1 . _id ; } if ( Reference . isReference ( value2 ) ) { var mapping2 = ( < Reference > value2 ) . mapping ; var id2 = ( < Reference > value2 ) . _id ; } else { var id2 = value2 . _id ; } if ( mapping1 == null && mapping2 == null ) return false ; if ( id1 == null || id2 == null ) return false ; return ( < EntityMapping > ( mapping1 || mapping2 ) . inheritanceRoot ) . identity . areEqual ( id1 , id2 ) ; } static isReference ( obj ) { return obj instanceof Reference ; } param session param obj param callback static fetch ( session , obj , callback ) { if ( Reference . isReference ( obj ) ) { ( < Reference > obj ) . fetch ( session , callback ) ; } else { callback ( null , obj ) ; } } }