-
Notifications
You must be signed in to change notification settings - Fork 734
Apps #9401
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
Apps #9401
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { Cascade, EntityName, ManyToOneOptions } from '@mikro-orm/core'; | ||
| import { omit } from 'underscore'; | ||
| import { deepClone, isObject } from '@gauzy/utils'; | ||
| import { MultiORMEnum, getORMType } from '../../../../core/utils'; | ||
| import { TypeOrmManyToOne } from './type-orm'; | ||
| import { MikroOrmManyToOne } from './mikro-orm'; | ||
| import { | ||
|
|
@@ -66,23 +67,30 @@ export function MultiORMManyToOne<T, O>( | |
| // If options are not provided, initialize an empty object | ||
| if (!options) options = {} as RelationOptions<T, O>; | ||
|
|
||
| // Use TypeORM decorator for Many-to-One | ||
| TypeOrmManyToOne( | ||
| typeFunctionOrTarget as TypeORMTarget<T>, | ||
| inverseSideOrOptions as TypeORMInverseSide<T>, | ||
| options as TypeORMRelationOptions | ||
| )(target, propertyKey); | ||
|
|
||
| // Use MikroORM decorator for Many-to-One | ||
| MikroOrmManyToOne( | ||
| mapManyToOneArgsForMikroORM({ | ||
| typeFunctionOrTarget, | ||
| inverseSideOrOptions: inverseSideProperty as InverseSide<T>, | ||
| options, | ||
| propertyKey, | ||
| target | ||
| }) | ||
| )(target, propertyKey); | ||
| // Determine which ORM is in use | ||
| const ormType = getORMType(); | ||
|
|
||
| // Apply TypeORM decorator when using TypeORM | ||
| if (ormType === MultiORMEnum.TypeORM) { | ||
| TypeOrmManyToOne( | ||
| typeFunctionOrTarget as TypeORMTarget<T>, | ||
| inverseSideOrOptions as TypeORMInverseSide<T>, | ||
| options as TypeORMRelationOptions | ||
| )(target, propertyKey); | ||
|
Comment on lines
+73
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P0] TypeORM ManyToOne decorator can receive the options object as the inverse-side argument. In Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/core/src/lib/core/decorators/entity/relations/many-to-one.decorator.ts
Line: 73:79
Comment:
[P0] TypeORM ManyToOne decorator can receive the *options object* as the inverse-side argument.
In `MultiORMManyToOne`, when `inverseSideOrOptions` is an object it is treated as `options` and `inverseSideProperty` remains unset, but the TypeORM branch still calls `TypeOrmManyToOne(..., inverseSideOrOptions as TypeORMInverseSide<T>, ...)`. Under TypeORM, calls like `MultiORMManyToOne(User, { nullable: true })` will pass that options object as the inverse side and likely break relation metadata registration.
How can I resolve this? If you propose a fix, please make it concise. |
||
| } | ||
|
|
||
| // Apply MikroORM decorator when using MikroORM | ||
| if (ormType === MultiORMEnum.MikroORM) { | ||
| MikroOrmManyToOne( | ||
| mapManyToOneArgsForMikroORM({ | ||
| typeFunctionOrTarget, | ||
| inverseSideOrOptions: inverseSideProperty as InverseSide<T>, | ||
| options, | ||
| propertyKey, | ||
| target | ||
| }) | ||
| )(target, propertyKey); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { Cascade, EntityName, OneToOneOptions } from '@mikro-orm/core'; | ||
| import { omit } from 'underscore'; | ||
| import { deepClone, isObject } from '@gauzy/utils'; | ||
| import { MultiORMEnum } from '../../../../core/utils'; | ||
| import { MultiORMEnum, getORMType } from '../../../../core/utils'; | ||
| import { | ||
| MikroORMInverseSide, | ||
| TypeORMInverseSide, | ||
|
|
@@ -67,22 +67,29 @@ export function MultiORMOneToOne<T, O>( | |
| // If options are not provided, initialize an empty object | ||
| if (!options) options = {} as RelationOptions<T, O>; | ||
|
|
||
| // Use TypeORM decorator for One-to-One | ||
| TypeOrmOneToOne( | ||
| typeFunctionOrTarget as TypeORMTarget<T>, | ||
| inverseSideOrOptions as TypeORMInverseSide<T>, | ||
| options as TypeORMRelationOptions | ||
| )(target, propertyKey); | ||
|
|
||
| // Use MikroORM decorator for One-to-One | ||
| MikroOrmOneToOne( | ||
| mapOneToOneArgsForMikroORM({ | ||
| typeFunctionOrTarget, | ||
| inverseSideOrOptions: inverseSideProperty as InverseSide<T>, | ||
| options, | ||
| propertyKey | ||
| }) | ||
| )(target, propertyKey); | ||
| // Determine which ORM is in use | ||
| const ormType = getORMType(); | ||
|
|
||
| // Apply TypeORM decorator when using TypeORM | ||
| if (ormType === MultiORMEnum.TypeORM) { | ||
| TypeOrmOneToOne( | ||
| typeFunctionOrTarget as TypeORMTarget<T>, | ||
| inverseSideOrOptions as TypeORMInverseSide<T>, | ||
| options as TypeORMRelationOptions | ||
| )(target, propertyKey); | ||
|
Comment on lines
+73
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P0] TypeORM OneToOne decorator can receive the options object as the inverse-side argument.
Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/core/src/lib/core/decorators/entity/relations/one-to-one.decorator.ts
Line: 73:79
Comment:
[P0] TypeORM OneToOne decorator can receive the *options object* as the inverse-side argument.
`MultiORMOneToOne` normalizes params such that if `inverseSideOrOptions` is an object it becomes `options` and `inverseSideProperty` remains unset, but the TypeORM branch still passes `inverseSideOrOptions` as the inverse-side arg. Under TypeORM, calls like `MultiORMOneToOne(Profile, { cascade: true })` will end up passing the options object as the inverse side, which can break relation metadata.
How can I resolve this? If you propose a fix, please make it concise. |
||
| } | ||
|
|
||
| // Apply MikroORM decorator when using MikroORM | ||
| if (ormType === MultiORMEnum.MikroORM) { | ||
| MikroOrmOneToOne( | ||
| mapOneToOneArgsForMikroORM({ | ||
| typeFunctionOrTarget, | ||
| inverseSideOrOptions: inverseSideProperty as InverseSide<T>, | ||
| options, | ||
| propertyKey | ||
| }) | ||
| )(target, propertyKey); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
|
|
||
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.
getORMType()is evaluated when decorators run (class definition time), so ifDB_ORMisn’t set before entity modules are imported it will default to TypeORM and skip registering MikroORM relation metadata. That can lead to missing relations in MikroORM runtime (or vice‑versa) depending on import order/config initialization.Other Locations
packages/core/src/lib/core/decorators/entity/relations/many-to-one.decorator.ts:71packages/core/src/lib/core/decorators/entity/relations/one-to-many.decorator.ts:60packages/core/src/lib/core/decorators/entity/relations/one-to-one.decorator.ts:71🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.