unconventional 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,7 +39,7 @@ export interface Relation<Target extends typeof BaseModel = any, Source extends
|
|
|
39
39
|
/** The type of relation */
|
|
40
40
|
type: RelationType;
|
|
41
41
|
/** The model to relate to */
|
|
42
|
-
model: Target;
|
|
42
|
+
model: Target | (() => Target);
|
|
43
43
|
/** The field on this model to use for the relation */
|
|
44
44
|
from: keyof InstanceType<Source>;
|
|
45
45
|
/** The field on the related model to use for the relation */
|
package/dist/utils/db.utils.js
CHANGED
|
@@ -19,16 +19,17 @@ function getExpand(model, expand) {
|
|
|
19
19
|
const relation = propSummary[parent]?.relation;
|
|
20
20
|
if (!relation)
|
|
21
21
|
throw api_error_1.APIError.errInvalidQueryParameter(`Invalid expansion: ${parent}`);
|
|
22
|
+
const relationModel = (relation.model.toString().startsWith('class')) ? relation.model : relation.model();
|
|
22
23
|
expansions[parent] = {
|
|
23
24
|
type: [decorator_types_1.RelationType.HasOne, decorator_types_1.RelationType.BelongsTo].includes(relation.type) ? unconventional_pg_queries_1.OneOrMany.One : unconventional_pg_queries_1.OneOrMany.Many,
|
|
24
25
|
fromTable: model.collection,
|
|
25
26
|
fromField: relation.from.toString(),
|
|
26
|
-
toTable:
|
|
27
|
+
toTable: relationModel.collection,
|
|
27
28
|
toField: relation.to.toString(),
|
|
28
29
|
throughTable: relation.through?.model.collection,
|
|
29
30
|
throughFromField: relation.through?.from.toString(),
|
|
30
31
|
throughToField: relation.through?.to.toString(),
|
|
31
|
-
expand: children ? getExpand(
|
|
32
|
+
expand: children ? getExpand(relationModel, children) : undefined
|
|
32
33
|
};
|
|
33
34
|
});
|
|
34
35
|
return expansions;
|