Skip to content

Commit

Permalink
fix(core): fix pull request review
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhussein committed May 13, 2020
1 parent 5163af1 commit 27da750
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/entity/EntityFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ export class EntityFactory {
/**
* denormalize PK to value required by driver (e.g. ObjectId)
*/
private denormalizePrimaryKey<T extends AnyEntity<T>>(data: EntityData<T>, primaryKey: string, metadata: EntityProperty ): void {
private denormalizePrimaryKey<T extends AnyEntity<T>>(data: EntityData<T>, primaryKey: string, prop: EntityProperty<T> ): void {
const platform = this.driver.getPlatform();
const pk = platform.getSerializedPrimaryKeyField(primaryKey);

if (Utils.isDefined(data[pk], true) || Utils.isDefined(data[primaryKey], true)) {
let id = data[pk] || data[primaryKey];
if(metadata.type.toLowerCase() === 'objectid') {

if(prop.type.toLowerCase() === 'objectid') {
id = platform.denormalizePrimaryKey(id);
}
delete data[pk];
Expand Down
1 change: 1 addition & 0 deletions packages/mongodb/src/MongoDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ export class MongoDriver extends DatabaseDriver<MongoConnection> {

private buildFilterById<T extends AnyEntity<T>>(entityName: string, id: string): FilterQuery<T> {
const meta = this.metadata.get(entityName);

if (meta.properties[meta.primaryKeys[0]].type.toLowerCase() === 'objectid') {
return { _id: new ObjectId(id) } as FilterQuery<T>;
}
Expand Down

0 comments on commit 27da750

Please sign in to comment.