Skip to content

Commit

Permalink
fix: check of relation type
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandrjet committed Apr 22, 2024
1 parent 0e2e3db commit f2fb9e5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/core/database/src/query/helpers/populate/apply.ts
Expand Up @@ -527,7 +527,7 @@ const morphToMany = async (input: Input<Relation.MorphToMany>, ctx: Context) =>
const ids = idsByType[type];

// type was removed but still in morph relation
if (!db.metadata.get(type)) {
if (!db.metadata.has(type)) {
map[type] = {};

continue;
Expand All @@ -551,6 +551,10 @@ const morphToMany = async (input: Input<Relation.MorphToMany>, ctx: Context) =>
const id = joinResult[idColumn.name] as ID;
const type = joinResult[typeColumn.name] as string;

if (!map[type][id]) {
return [];
}

const targetMeta = db.metadata.get(type);

const fromTargetRow = (rowOrRows: Row | Row[] | undefined) => fromRow(targetMeta, rowOrRows);
Expand Down Expand Up @@ -601,7 +605,7 @@ const morphToOne = async (input: Input<Relation.MorphToOne>, ctx: Context) => {
const ids = idsByType[type];

// type was removed but still in morph relation
if (!db.metadata.get(type)) {
if (!db.metadata.has(type)) {
map[type] = {};
return;
}
Expand All @@ -621,7 +625,7 @@ const morphToOne = async (input: Input<Relation.MorphToOne>, ctx: Context) => {
const id = result[idColumn.name] as ID;
const type = result[typeColumn.name] as string;

if (!type || !id) {
if (!type || !id || !map[type][id]) {
result[attributeName] = null;
return;
}
Expand Down

0 comments on commit f2fb9e5

Please sign in to comment.