import {RelationOptions} from "../options/RelationOptions"; import {RelationTypes} from "../../metadata/types/RelationTypes"; import {getMetadataArgsStorage} from "../../../index"; import {ObjectType} from "../../common/ObjectType"; import {RelationMetadataArgs} from "../../metadata-args/RelationMetadataArgs"; /** * Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have * multiple instances of Entity1. To achieve it, this type of relation creates a junction table, where it storage * entity1 and entity2 ids. This is owner side of the relationship. */ export function ManyToMany(typeFunction: (type?: any) => ObjectType, options?: RelationOptions): Function; /** * Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have * multiple instances of Entity1. To achieve it, this type of relation creates a junction table, where it storage * entity1 and entity2 ids. This is owner side of the relationship. */ export function ManyToMany(typeFunction: (type?: any) => ObjectType, inverseSide?: string|((object: T) => any), options?: RelationOptions): Function; /** * Many-to-many is a type of relationship when Entity1 can have multiple instances of Entity2, and Entity2 can have * multiple instances of Entity1. To achieve it, this type of relation creates a junction table, where it storage * entity1 and entity2 ids. This is owner side of the relationship. */ export function ManyToMany(typeFunction: (type?: any) => ObjectType, inverseSideOrOptions?: string|((object: T) => any)|RelationOptions, options?: RelationOptions): Function { let inverseSideProperty: string|((object: T) => any); if (typeof inverseSideOrOptions === "object") { options = inverseSideOrOptions; } else { inverseSideProperty = any)> inverseSideOrOptions; } return function (object: Object, propertyName: string) { if (!options) options = {} as RelationOptions; const reflectedType = (Reflect as any).getMetadata("design:type", object, propertyName); const isLazy = reflectedType && typeof reflectedType.name === "string" && reflectedType.name.toLowerCase() === "promise"; const args: RelationMetadataArgs = { target: object.constructor, propertyName: propertyName, propertyType: reflectedType, relationType: RelationTypes.MANY_TO_MANY, isLazy: isLazy, type: typeFunction, inverseSideProperty: inverseSideProperty, options: options }; getMetadataArgsStorage().relations.add(args); }; }