-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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(core): self-referencing relations Not unique table/alias
#2740
Conversation
if (!currentParentIsTreeType && !currentMetadataIsTreeType) { | ||
let currentMetadataHasOneOrMoreSelfReferencingRelations = false; | ||
// Check if the current entity has one or more self-referencing relations | ||
// to determine if it is a tree type or has tree relations. | ||
for (const relation of currentMetadata.relations) { | ||
if (relation.inverseEntityMetadata === currentMetadata) { | ||
currentMetadataHasOneOrMoreSelfReferencingRelations = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!currentParentIsTreeType && !currentMetadataIsTreeType && !currentMetadataHasOneOrMoreSelfReferencingRelations) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most important code. It is enough to determine whether it is necessary to do join manually or leave this job to typeorm
|
||
@ManyToOne(() => TestEntity, (type) => type.parent) | ||
parent: TestEntity | null; | ||
|
||
@Column('int', { nullable: true }) | ||
parentId: ID | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I had to update the model a bit to repeat the error and take it into account in the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
above fix i think need consider more behavior
if we have translations
like
@OneToMany(
() => LensProcessOptionTranslation,
(translation) => translation.base,
{ eager: true }
)
translations: Array<Translation<LensProcessOption>>;
the parent
should be auto load translations
otherwise it will result translateEntity
failed
function translateLeaf(
object: { [key: string]: any } | undefined,
property: string,
languageCode: LanguageCode | [LanguageCode, ...LanguageCode[]],
): any {
if (object && object[property]) {
if (Array.isArray(object[property])) {
return object[property].map((nested2: any) => translateEntity(nested2, languageCode));
} else if (object[property]) {
return translateEntity(object[property], languageCode);
}
}
}
if parent
existed but it have auto loaded translations
it will broken here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please see my latest updated repo https://github.com/tianyingchun/next-issue/tree/vendure_issue_2738
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InternalServerError [GraphQLError]: error.entity-has-no-translation-in-language
at new I18nError (/Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/node_modules/@vendure/core/dist/i18n/i18n-error.js:21:9)
at new InternalServerError (/Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/node_modules/@vendure/core/dist/common/error/errors.js:15:9)
at translateEntity (/Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/node_modules/@vendure/core/dist/service/helpers/utils/translate-entity.js:33:15)
at translateLeaf (/Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/node_modules/@vendure/core/dist/service/helpers/utils/translate-entity.js:104:20)
at translateDeep (/Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/node_modules/@vendure/core/dist/service/helpers/utils/translate-entity.js:89:21)
at TranslatorService.translate (/Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/node_modules/@vendure/core/dist/service/helpers/translator/translator.service.js:54:53)
at file:///Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/packages/plugin-issue/src/services/menu.service.ts:82:76
at Array.map (<anonymous>)
at file:///Users/tianyingchun/Documents/coding/kzfoo/vendure-issue/packages/plugin-issue/src/services/menu.service.ts:82:37
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
path: undefined,
locations: undefined,
extensions: { code: 'INTERNAL_SERVER_ERROR' },
variables: { entityName: 'Menu', languageCode: ',,en' },
code: 'INTERNAL_SERVER_ERROR',
logLevel: 0
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I thought I had accounted for translations for all self-related relations. I will look into this and add join for eager relations
above fix i think need consider more behavior if we have
translations
like@OneToMany( () => LensProcessOptionTranslation, (translation) => translation.base, { eager: true } ) translations: Array<Translation<LensProcessOption>>;the
parent
should be auto loadtranslations
otherwise it will resulttranslateEntity
failedfunction translateLeaf( object: { [key: string]: any } | undefined, property: string, languageCode: LanguageCode | [LanguageCode, ...LanguageCode[]], ): any { if (object && object[property]) { if (Array.isArray(object[property])) { return object[property].map((nested2: any) => translateEntity(nested2, languageCode)); } else if (object[property]) { return translateEntity(object[property], languageCode); } } }if
parent
existed but it have auto loadedtranslations
it will broken here
@michaelbromley I'm not sure if we should look for translation in nested objects automatically because that would lead to uncontrolled execution of this method.
|
Can you also provide the missing code from
|
/**
* @description
* Entities which can be assigned to Module Channels should implement this interface.
*/
export interface ModuleChannelAware {
channels: ModuleChannel[];
} |
@michaelbromley In this PR, the first bug has been fixed. I'll open a new PR from #2744 |
357ba49
into
vendure-ecommerce:minor
@monrostar yep, makes sense to split the other changes. @tianyingchun thank you very much for the ongoing feedback! |
Description
This code bypasses the typeorm bug related to an error in duplicate aliases when linking to a parent table
Related issue: #2738
Breaking changes
Does this PR include any breaking changes we should be aware of?
Checklist
📌 Always:
👍 Most of the time: