Skip to content

Commit

Permalink
Merge pull request #273 from RWOverdijk/feat/remove-recipe
Browse files Browse the repository at this point in the history
feat(Hydrator): add removeRecipe
  • Loading branch information
RWOverdijk committed Mar 29, 2019
2 parents 9ccd5f5 + a560d50 commit 9b5ae8e
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/Hydrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class Hydrator {
/**
* Get a recipe.
*
* @param {string}alias
* @param {string} alias
* @returns {any}
*/
public getRecipe(alias?): Recipe {
Expand All @@ -102,6 +102,23 @@ export class Hydrator {
return this.recipe;
}

/**
* Completely remove a recipe.
*
* @param {string} alias
*
* @returns {void}
*/
public removeRecipe(alias): void {
const recipe = this.recipeIndex[alias];

if (recipe && recipe.parentRecipe) {
delete recipe.parentRecipe.joins[alias];
}

delete this.recipeIndex[alias];
}

/**
* Add a recipe to the hydrator.
*
Expand All @@ -116,7 +133,7 @@ export class Hydrator {
public addRecipe(parent: null | string, alias: string, mapping: Mapping<Entity>, joinType?: string, property?: string): Recipe {
const primaryKey = mapping.getPrimaryKey();
const primaryKeyAliased = `${alias}.${primaryKey}`;
const recipe = {
const recipe: Recipe = {
hydrate: false,
parent: null,
entity: mapping.getTarget() as EntityCtor<EntityInterface>,
Expand All @@ -133,6 +150,7 @@ export class Hydrator {
const parentRecipe = this.recipeIndex[parent];
parentRecipe.joins = parentRecipe.joins || {};
parentRecipe.joins[alias] = recipe;
recipe.parentRecipe = parentRecipe;
} else {
this.recipe = recipe;
}
Expand Down Expand Up @@ -363,6 +381,7 @@ export interface Recipe {
columns: {};
catalogue?: Catalogue;
parent?: { property: string, column: string, entities: Object };
parentRecipe?: Recipe;
joins?: { [key: string]: Recipe };
property?: string;
type?: string;
Expand Down

0 comments on commit 9b5ae8e

Please sign in to comment.