Permalink
Browse files

fix(UnitOfWork): Use entity reference when proxy

  • Loading branch information...
RWOverdijk committed Oct 7, 2016
1 parent cfda83d commit 86e6fb596836d8375362c3acaaf5c3bd4265d4da
Showing with 5 additions and 4 deletions.
  1. +5 −4 src/UnitOfWork.ts
@@ -302,13 +302,14 @@ export class UnitOfWork {
/**
* set the state of an entity.
*
* @param {EntityInterface} entity
* @param {ProxyInterface} entity
* @param {string} state
*
* @returns {UnitOfWork}
*/
public setEntityState(entity: EntityInterface, state: string): UnitOfWork {
public setEntityState(entity: ProxyInterface, state: string): UnitOfWork {
let metaData = MetaData.forInstance(entity);
let target = entity.isEntityProxy ? entity.getTarget : entity;
let previousState = metaData.fetch('entityState.state', UnitOfWork.STATE_UNKNOWN);
if (previousState === state) {
@@ -321,10 +322,10 @@ export class UnitOfWork {
}
if (previousState !== UnitOfWork.STATE_UNKNOWN) {
this[`${previousState}Objects`].remove(entity);
this[`${previousState}Objects`].remove(target);
}
this[`${state}Objects`].add(entity);
this[`${state}Objects`].add(target);
metaData.put('entityState.state', state);

0 comments on commit 86e6fb5

Please sign in to comment.