1 | import { RelationType } from "./types/RelationTypes";
|
2 | import { EntityMetadata } from "./EntityMetadata";
|
3 | import { ForeignKeyMetadata } from "./ForeignKeyMetadata";
|
4 | import { ObjectLiteral } from "../common/ObjectLiteral";
|
5 | import { ColumnMetadata } from "./ColumnMetadata";
|
6 | import { EmbeddedMetadata } from "./EmbeddedMetadata";
|
7 | import { RelationMetadataArgs } from "../metadata-args/RelationMetadataArgs";
|
8 | import { DeferrableType } from "./types/DeferrableType";
|
9 | import { OnUpdateType } from "./types/OnUpdateType";
|
10 | import { OnDeleteType } from "./types/OnDeleteType";
|
11 | import { PropertyTypeFactory } from "./types/PropertyTypeInFunction";
|
12 | /**
|
13 | * Contains all information about some entity's relation.
|
14 | */
|
15 | export declare class RelationMetadata {
|
16 | /**
|
17 | * Entity metadata of the entity where this relation is placed.
|
18 | *
|
19 | * For example for @ManyToMany(type => Category) in Post, entityMetadata will be metadata of Post entity.
|
20 | */
|
21 | entityMetadata: EntityMetadata;
|
22 | /**
|
23 | * Entity metadata of the entity that is targeted by this relation.
|
24 | *
|
25 | * For example for @ManyToMany(type => Category) in Post, inverseEntityMetadata will be metadata of Category entity.
|
26 | */
|
27 | inverseEntityMetadata: EntityMetadata;
|
28 | /**
|
29 | * Entity metadata of the junction table.
|
30 | * Junction tables have their own entity metadata objects.
|
31 | * Defined only for many-to-many relations.
|
32 | */
|
33 | junctionEntityMetadata?: EntityMetadata;
|
34 | /**
|
35 | * Embedded metadata where this relation is.
|
36 | * If this relation is not in embed then this property value is undefined.
|
37 | */
|
38 | embeddedMetadata?: EmbeddedMetadata;
|
39 | /**
|
40 | * Relation type, e.g. is it one-to-one, one-to-many, many-to-one or many-to-many.
|
41 | */
|
42 | relationType: RelationType;
|
43 | /**
|
44 | * Target entity to which this relation is applied.
|
45 | * Target IS NOT equal to entityMetadata.target, because relation
|
46 | *
|
47 | * For example for @ManyToMany(type => Category) in Post, target will be Post.
|
48 | * If @ManyToMany(type => Category) is in Counters which is embedded into Post, target will be Counters.
|
49 | * If @ManyToMany(type => Category) is in abstract class BaseUser which Post extends, target will be BaseUser.
|
50 | * Target can be string if its defined in entity schema instead of class.
|
51 | */
|
52 | target: Function | string;
|
53 | /**
|
54 | * Target's property name to which relation decorator is applied.
|
55 | */
|
56 | propertyName: string;
|
57 | /**
|
58 | * Gets full path to this column property (including relation name).
|
59 | * Full path is relevant when column is used in embeds (one or multiple nested).
|
60 | * For example it will return "counters.subcounters.likes".
|
61 | * If property is not in embeds then it returns just property name of the column.
|
62 | */
|
63 | propertyPath: string;
|
64 | /**
|
65 | * Indicates if this is a parent (can be only many-to-one relation) relation in the tree tables.
|
66 | */
|
67 | isTreeParent: boolean;
|
68 | /**
|
69 | * Indicates if this is a children (can be only one-to-many relation) relation in the tree tables.
|
70 | */
|
71 | isTreeChildren: boolean;
|
72 | /**
|
73 | * Indicates if this relation's column is a primary key.
|
74 | * Can be used only for many-to-one and owner one-to-one relations.
|
75 | */
|
76 | isPrimary: boolean;
|
77 | /**
|
78 | * Indicates if this relation is lazily loaded.
|
79 | */
|
80 | isLazy: boolean;
|
81 | /**
|
82 | * Indicates if this relation is eagerly loaded.
|
83 | */
|
84 | isEager: boolean;
|
85 | /**
|
86 | * Indicates if persistence is enabled for the relation.
|
87 | * By default its enabled, but if you want to avoid any changes in the relation to be reflected in the database you can disable it.
|
88 | * If its disabled you can only change a relation from inverse side of a relation or using relation query builder functionality.
|
89 | * This is useful for performance optimization since its disabling avoid multiple extra queries during entity save.
|
90 | */
|
91 | persistenceEnabled: boolean;
|
92 | /**
|
93 | * If set to true then related objects are allowed to be inserted to the database.
|
94 | */
|
95 | isCascadeInsert: boolean;
|
96 | /**
|
97 | * If set to true then related objects are allowed to be updated in the database.
|
98 | */
|
99 | isCascadeUpdate: boolean;
|
100 | /**
|
101 | * If set to true then related objects are allowed to be remove from the database.
|
102 | */
|
103 | isCascadeRemove: boolean;
|
104 | /**
|
105 | * Indicates if relation column value can be nullable or not.
|
106 | */
|
107 | isNullable: boolean;
|
108 | /**
|
109 | * What to do with a relation on deletion of the row containing a foreign key.
|
110 | */
|
111 | onDelete?: OnDeleteType;
|
112 | /**
|
113 | * What to do with a relation on update of the row containing a foreign key.
|
114 | */
|
115 | onUpdate?: OnUpdateType;
|
116 | /**
|
117 | * What to do with a relation on update of the row containing a foreign key.
|
118 | */
|
119 | deferrable?: DeferrableType;
|
120 | /**
|
121 | * Gets the property's type to which this relation is applied.
|
122 | *
|
123 | * For example for @ManyToMany(type => Category) in Post, target will be Category.
|
124 | */
|
125 | type: Function | string;
|
126 | /**
|
127 | * Indicates if this side is an owner of this relation.
|
128 | */
|
129 | isOwning: boolean;
|
130 | /**
|
131 | * Checks if this relation's type is "one-to-one".
|
132 | */
|
133 | isOneToOne: boolean;
|
134 | /**
|
135 | * Checks if this relation is owner side of the "one-to-one" relation.
|
136 | * Owner side means this side of relation has a join column in the table.
|
137 | */
|
138 | isOneToOneOwner: boolean;
|
139 | /**
|
140 | * Checks if this relation has a join column (e.g. is it many-to-one or one-to-one owner side).
|
141 | */
|
142 | isWithJoinColumn: boolean;
|
143 | /**
|
144 | * Checks if this relation is NOT owner side of the "one-to-one" relation.
|
145 | * NOT owner side means this side of relation does not have a join column in the table.
|
146 | */
|
147 | isOneToOneNotOwner: boolean;
|
148 | /**
|
149 | * Checks if this relation's type is "one-to-many".
|
150 | */
|
151 | isOneToMany: boolean;
|
152 | /**
|
153 | * Checks if this relation's type is "many-to-one".
|
154 | */
|
155 | isManyToOne: boolean;
|
156 | /**
|
157 | * Checks if this relation's type is "many-to-many".
|
158 | */
|
159 | isManyToMany: boolean;
|
160 | /**
|
161 | * Checks if this relation's type is "many-to-many", and is owner side of the relationship.
|
162 | * Owner side means this side of relation has a join table.
|
163 | */
|
164 | isManyToManyOwner: boolean;
|
165 | /**
|
166 | * Checks if this relation's type is "many-to-many", and is NOT owner side of the relationship.
|
167 | * Not owner side means this side of relation does not have a join table.
|
168 | */
|
169 | isManyToManyNotOwner: boolean;
|
170 | /**
|
171 | * Gets the property path of the inverse side of the relation.
|
172 | */
|
173 | inverseSidePropertyPath: string;
|
174 | /**
|
175 | * Inverse side of the relation set by user.
|
176 | *
|
177 | * Inverse side set in the relation can be either string - property name of the column on inverse side,
|
178 | * either can be a function that accepts a map of properties with the object and returns one of them.
|
179 | * Second approach is used to achieve type-safety.
|
180 | */
|
181 | givenInverseSidePropertyFactory: PropertyTypeFactory<any>;
|
182 | /**
|
183 | * Gets the relation metadata of the inverse side of this relation.
|
184 | */
|
185 | inverseRelation?: RelationMetadata;
|
186 | /**
|
187 | * Join table name.
|
188 | */
|
189 | joinTableName: string;
|
190 | /**
|
191 | * Foreign keys created for this relation.
|
192 | */
|
193 | foreignKeys: ForeignKeyMetadata[];
|
194 | /**
|
195 | * Join table columns.
|
196 | * Join columns can be obtained only from owner side of the relation.
|
197 | * From non-owner side of the relation join columns will be empty.
|
198 | * If this relation is a many-to-one/one-to-one then it takes join columns from the current entity.
|
199 | * If this relation is many-to-many then it takes all owner join columns from the junction entity.
|
200 | */
|
201 | joinColumns: ColumnMetadata[];
|
202 | /**
|
203 | * Inverse join table columns.
|
204 | * Inverse join columns are supported only for many-to-many relations
|
205 | * and can be obtained only from owner side of the relation.
|
206 | * From non-owner side of the relation join columns will be undefined.
|
207 | */
|
208 | inverseJoinColumns: ColumnMetadata[];
|
209 | constructor(options: {
|
210 | entityMetadata: EntityMetadata;
|
211 | embeddedMetadata?: EmbeddedMetadata;
|
212 | args: RelationMetadataArgs;
|
213 | });
|
214 | /**
|
215 | * Creates join column ids map from the given related entity ids array.
|
216 | */
|
217 | getRelationIdMap(entity: ObjectLiteral): ObjectLiteral | undefined;
|
218 | /**
|
219 | * Ensures that given object is an entity id map.
|
220 | * If given id is an object then it means its already id map.
|
221 | * If given id isn't an object then it means its a value of the id column
|
222 | * and it creates a new id map with this value and name of the primary column.
|
223 | */
|
224 | ensureRelationIdMap(id: any): ObjectLiteral;
|
225 | /**
|
226 | * Extracts column value from the given entity.
|
227 | * If column is in embedded (or recursive embedded) it extracts its value from there.
|
228 | */
|
229 | getEntityValue(entity: ObjectLiteral, getLazyRelationsPromiseValue?: boolean): any | undefined;
|
230 | /**
|
231 | * Sets given entity's relation's value.
|
232 | * Using of this method helps to set entity relation's value of the lazy and non-lazy relations.
|
233 | *
|
234 | * If merge is set to true, it merges given value into currently
|
235 | */
|
236 | setEntityValue(entity: ObjectLiteral, value: any): void;
|
237 | /**
|
238 | * Creates entity id map from the given entity ids array.
|
239 | */
|
240 | createValueMap(value: any): any;
|
241 | /**
|
242 | * Builds some depend relation metadata properties.
|
243 | * This builder method should be used only after embedded metadata tree was build.
|
244 | */
|
245 | build(): void;
|
246 | /**
|
247 | * Registers given foreign keys in the relation.
|
248 | * This builder method should be used to register foreign key in the relation.
|
249 | */
|
250 | registerForeignKeys(...foreignKeys: ForeignKeyMetadata[]): void;
|
251 | /**
|
252 | * Registers a given junction entity metadata.
|
253 | * This builder method can be called after junction entity metadata for the many-to-many relation was created.
|
254 | */
|
255 | registerJunctionEntityMetadata(junctionEntityMetadata: EntityMetadata): void;
|
256 | /**
|
257 | * Builds inverse side property path based on given inverse side property factory.
|
258 | * This builder method should be used only after properties map of the inverse entity metadata was build.
|
259 | */
|
260 | buildInverseSidePropertyPath(): string;
|
261 | /**
|
262 | * Builds relation's property path based on its embedded tree.
|
263 | */
|
264 | buildPropertyPath(): string;
|
265 | }
|