Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: checking for relation type existence #20167

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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