@orchestr-sh/orchestr 1.5.10 → 1.5.11
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.
- package/README.md +275 -977
- package/dist/Database/Ensemble/Concerns/HasDynamicRelations.d.ts +5 -0
- package/dist/Database/Ensemble/Concerns/HasDynamicRelations.d.ts.map +1 -1
- package/dist/Database/Ensemble/Concerns/HasDynamicRelations.js.map +1 -1
- package/dist/Database/Ensemble/Concerns/HasRelationships.d.ts +20 -0
- package/dist/Database/Ensemble/Concerns/HasRelationships.d.ts.map +1 -1
- package/dist/Database/Ensemble/Concerns/HasRelationships.js +57 -0
- package/dist/Database/Ensemble/Concerns/HasRelationships.js.map +1 -1
- package/dist/Database/Ensemble/Relations/MorphMany.d.ts +97 -0
- package/dist/Database/Ensemble/Relations/MorphMany.d.ts.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphMany.js +189 -0
- package/dist/Database/Ensemble/Relations/MorphMany.js.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphMap.d.ts +59 -0
- package/dist/Database/Ensemble/Relations/MorphMap.d.ts.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphMap.js +84 -0
- package/dist/Database/Ensemble/Relations/MorphMap.js.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphOne.d.ts +93 -0
- package/dist/Database/Ensemble/Relations/MorphOne.d.ts.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphOne.js +179 -0
- package/dist/Database/Ensemble/Relations/MorphOne.js.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphTo.d.ts +98 -0
- package/dist/Database/Ensemble/Relations/MorphTo.d.ts.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphTo.js +214 -0
- package/dist/Database/Ensemble/Relations/MorphTo.js.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphToMany.d.ts +73 -0
- package/dist/Database/Ensemble/Relations/MorphToMany.d.ts.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphToMany.js +164 -0
- package/dist/Database/Ensemble/Relations/MorphToMany.js.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphedByMany.d.ts +29 -0
- package/dist/Database/Ensemble/Relations/MorphedByMany.d.ts.map +1 -0
- package/dist/Database/Ensemble/Relations/MorphedByMany.js +58 -0
- package/dist/Database/Ensemble/Relations/MorphedByMany.js.map +1 -0
- package/dist/Database/Ensemble/Relations/index.d.ts +6 -0
- package/dist/Database/Ensemble/Relations/index.d.ts.map +1 -1
- package/dist/Database/Ensemble/Relations/index.js +14 -1
- package/dist/Database/Ensemble/Relations/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MorphOne Relationship
|
|
3
|
+
*
|
|
4
|
+
* Represents a polymorphic one-to-one relationship
|
|
5
|
+
* Example: Post has one Image (where Image belongs to many types)
|
|
6
|
+
*/
|
|
7
|
+
import { Ensemble } from '../Ensemble';
|
|
8
|
+
import { EnsembleBuilder } from '../EnsembleBuilder';
|
|
9
|
+
import { EnsembleCollection } from '../EnsembleCollection';
|
|
10
|
+
import { Relation } from './Relation';
|
|
11
|
+
export declare class MorphOne<TRelated extends Ensemble, TParent extends Ensemble> extends Relation<TRelated, TParent> {
|
|
12
|
+
/**
|
|
13
|
+
* The foreign key of the parent model (e.g., 'imageable_id')
|
|
14
|
+
*/
|
|
15
|
+
protected foreignKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* The morph type column (e.g., 'imageable_type')
|
|
18
|
+
*/
|
|
19
|
+
protected morphType: string;
|
|
20
|
+
/**
|
|
21
|
+
* The local key of the parent model
|
|
22
|
+
*/
|
|
23
|
+
protected localKey: string;
|
|
24
|
+
/**
|
|
25
|
+
* The morph class name or alias
|
|
26
|
+
*/
|
|
27
|
+
protected morphClass: string;
|
|
28
|
+
/**
|
|
29
|
+
* Create a new morph one relationship instance
|
|
30
|
+
*/
|
|
31
|
+
constructor(query: EnsembleBuilder<TRelated>, parent: TParent, name: string, type: string | null, id: string | null, localKey: string);
|
|
32
|
+
/**
|
|
33
|
+
* Set the base constraints on the relation query
|
|
34
|
+
*/
|
|
35
|
+
addConstraints(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Set the constraints for an eager load of the relation
|
|
38
|
+
*/
|
|
39
|
+
addEagerConstraints(models: TParent[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* Initialize the relation on a set of models
|
|
42
|
+
*/
|
|
43
|
+
initRelation(models: TParent[], relation: string): TParent[];
|
|
44
|
+
/**
|
|
45
|
+
* Match the eagerly loaded results to their parents
|
|
46
|
+
*/
|
|
47
|
+
match(models: TParent[], results: EnsembleCollection<TRelated>, relation: string): TParent[];
|
|
48
|
+
/**
|
|
49
|
+
* Build model dictionary keyed by the relation's foreign key
|
|
50
|
+
*/
|
|
51
|
+
protected buildDictionary(results: EnsembleCollection<TRelated>): Record<any, TRelated[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the results of the relationship
|
|
54
|
+
*/
|
|
55
|
+
getResults(): Promise<TRelated | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Get the key value of the parent's local key
|
|
58
|
+
*/
|
|
59
|
+
protected getParentKey(): any;
|
|
60
|
+
/**
|
|
61
|
+
* Get the morph class for the parent
|
|
62
|
+
*/
|
|
63
|
+
protected getMorphClass(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Get the foreign key for the relationship
|
|
66
|
+
*/
|
|
67
|
+
getForeignKeyName(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Get the morph type for the relationship
|
|
70
|
+
*/
|
|
71
|
+
getMorphType(): string;
|
|
72
|
+
/**
|
|
73
|
+
* Get the local key for the relationship
|
|
74
|
+
*/
|
|
75
|
+
getLocalKeyName(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Make a new related instance
|
|
78
|
+
*/
|
|
79
|
+
make(attributes?: Record<string, any>): TRelated;
|
|
80
|
+
/**
|
|
81
|
+
* Create a new instance of the related model
|
|
82
|
+
*/
|
|
83
|
+
create(attributes?: Record<string, any>): Promise<TRelated>;
|
|
84
|
+
/**
|
|
85
|
+
* Save a model and set the foreign key and morph type
|
|
86
|
+
*/
|
|
87
|
+
save(model: TRelated): Promise<TRelated>;
|
|
88
|
+
/**
|
|
89
|
+
* Update the parent model on the relationship
|
|
90
|
+
*/
|
|
91
|
+
update(attributes: Record<string, any>): Promise<number>;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=MorphOne.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MorphOne.d.ts","sourceRoot":"","sources":["../../../../src/Database/Ensemble/Relations/MorphOne.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,qBAAa,QAAQ,CAAC,QAAQ,SAAS,QAAQ,EAAE,OAAO,SAAS,QAAQ,CAAE,SAAQ,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC5G;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAE7B;;OAEG;gBAED,KAAK,EAAE,eAAe,CAAC,QAAQ,CAAC,EAChC,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,EAAE,EAAE,MAA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
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MorphOne Relationship
|
|
4
|
+
*
|
|
5
|
+
* Represents a polymorphic one-to-one relationship
|
|
6
|
+
* Example: Post has one Image (where Image belongs to many types)
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MorphOne = void 0;
|
|
10
|
+
const Relation_1 = require("./Relation");
|
|
11
|
+
const MorphMap_1 = require("./MorphMap");
|
|
12
|
+
class MorphOne extends Relation_1.Relation {
|
|
13
|
+
/**
|
|
14
|
+
* The foreign key of the parent model (e.g., 'imageable_id')
|
|
15
|
+
*/
|
|
16
|
+
foreignKey;
|
|
17
|
+
/**
|
|
18
|
+
* The morph type column (e.g., 'imageable_type')
|
|
19
|
+
*/
|
|
20
|
+
morphType;
|
|
21
|
+
/**
|
|
22
|
+
* The local key of the parent model
|
|
23
|
+
*/
|
|
24
|
+
localKey;
|
|
25
|
+
/**
|
|
26
|
+
* The morph class name or alias
|
|
27
|
+
*/
|
|
28
|
+
morphClass;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new morph one relationship instance
|
|
31
|
+
*/
|
|
32
|
+
constructor(query, parent, name, type, id, localKey) {
|
|
33
|
+
super(query, parent);
|
|
34
|
+
this.morphType = type || `${name}_type`;
|
|
35
|
+
this.foreignKey = id || `${name}_id`;
|
|
36
|
+
this.localKey = localKey;
|
|
37
|
+
this.morphClass = this.getMorphClass();
|
|
38
|
+
this.initializeRelation();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Set the base constraints on the relation query
|
|
42
|
+
*/
|
|
43
|
+
addConstraints() {
|
|
44
|
+
if (Relation_1.Relation['constraints']) {
|
|
45
|
+
const parentKey = this.getParentKey();
|
|
46
|
+
// Only add constraints if parent key exists
|
|
47
|
+
if (parentKey !== null && parentKey !== undefined) {
|
|
48
|
+
this.query
|
|
49
|
+
.where(this.foreignKey, '=', parentKey)
|
|
50
|
+
.where(this.morphType, '=', this.morphClass);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Set the constraints for an eager load of the relation
|
|
56
|
+
*/
|
|
57
|
+
addEagerConstraints(models) {
|
|
58
|
+
const keys = this.getKeys(models, this.localKey);
|
|
59
|
+
this.query
|
|
60
|
+
.whereIn(this.foreignKey, keys)
|
|
61
|
+
.where(this.morphType, '=', this.morphClass);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Initialize the relation on a set of models
|
|
65
|
+
*/
|
|
66
|
+
initRelation(models, relation) {
|
|
67
|
+
for (const model of models) {
|
|
68
|
+
model.setRelation(relation, null);
|
|
69
|
+
}
|
|
70
|
+
return models;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Match the eagerly loaded results to their parents
|
|
74
|
+
*/
|
|
75
|
+
match(models, results, relation) {
|
|
76
|
+
const dictionary = this.buildDictionary(results);
|
|
77
|
+
for (const model of models) {
|
|
78
|
+
const key = model.getAttribute(this.localKey);
|
|
79
|
+
if (key !== null && key !== undefined && dictionary[key]) {
|
|
80
|
+
model.setRelation(relation, dictionary[key][0]);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return models;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build model dictionary keyed by the relation's foreign key
|
|
87
|
+
*/
|
|
88
|
+
buildDictionary(results) {
|
|
89
|
+
const dictionary = {};
|
|
90
|
+
for (const result of results) {
|
|
91
|
+
const key = result.getAttribute(this.foreignKey);
|
|
92
|
+
if (key !== null && key !== undefined) {
|
|
93
|
+
if (!dictionary[key]) {
|
|
94
|
+
dictionary[key] = [];
|
|
95
|
+
}
|
|
96
|
+
dictionary[key].push(result);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return dictionary;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the results of the relationship
|
|
103
|
+
*/
|
|
104
|
+
async getResults() {
|
|
105
|
+
if (!this.getParentKey()) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
this.ensureConstraints();
|
|
109
|
+
return this.query.first();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the key value of the parent's local key
|
|
113
|
+
*/
|
|
114
|
+
getParentKey() {
|
|
115
|
+
return this.parent.getAttribute(this.localKey);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get the morph class for the parent
|
|
119
|
+
*/
|
|
120
|
+
getMorphClass() {
|
|
121
|
+
return MorphMap_1.MorphMap.getMorphedModel(this.parent);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get the foreign key for the relationship
|
|
125
|
+
*/
|
|
126
|
+
getForeignKeyName() {
|
|
127
|
+
return this.foreignKey;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get the morph type for the relationship
|
|
131
|
+
*/
|
|
132
|
+
getMorphType() {
|
|
133
|
+
return this.morphType;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Get the local key for the relationship
|
|
137
|
+
*/
|
|
138
|
+
getLocalKeyName() {
|
|
139
|
+
return this.localKey;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Make a new related instance
|
|
143
|
+
*/
|
|
144
|
+
make(attributes = {}) {
|
|
145
|
+
return this.related.newInstance(attributes);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Create a new instance of the related model
|
|
149
|
+
*/
|
|
150
|
+
async create(attributes = {}) {
|
|
151
|
+
const instance = this.make(attributes);
|
|
152
|
+
// Set both the foreign key and morph type
|
|
153
|
+
instance.setAttribute(this.foreignKey, this.getParentKey());
|
|
154
|
+
instance.setAttribute(this.morphType, this.morphClass);
|
|
155
|
+
await instance.save();
|
|
156
|
+
return instance;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Save a model and set the foreign key and morph type
|
|
160
|
+
*/
|
|
161
|
+
async save(model) {
|
|
162
|
+
model.setAttribute(this.foreignKey, this.getParentKey());
|
|
163
|
+
model.setAttribute(this.morphType, this.morphClass);
|
|
164
|
+
await model.save();
|
|
165
|
+
return model;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Update the parent model on the relationship
|
|
169
|
+
*/
|
|
170
|
+
async update(attributes) {
|
|
171
|
+
const updatedAtColumn = this.related.getUpdatedAtColumn();
|
|
172
|
+
if (updatedAtColumn) {
|
|
173
|
+
attributes[updatedAtColumn] = new Date();
|
|
174
|
+
}
|
|
175
|
+
return this.query.update(attributes);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.MorphOne = MorphOne;
|
|
179
|
+
//# sourceMappingURL=MorphOne.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MorphOne.js","sourceRoot":"","sources":["../../../../src/Database/Ensemble/Relations/MorphOne.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAKH,yCAAsC;AACtC,yCAAsC;AAEtC,MAAa,QAA8D,SAAQ,mBAA2B;IAC5G;;OAEG;IACO,UAAU,CAAS;IAE7B;;OAEG;IACO,SAAS,CAAS;IAE5B;;OAEG;IACO,QAAQ,CAAS;IAE3B;;OAEG;IACO,UAAU,CAAS;IAE7B;;OAEG;IACH,YACE,KAAgC,EAChC,MAAe,EACf,IAAY,EACZ,IAAmB,EACnB,EAAiB,EACjB,QAAgB;QAEhB,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAErB,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,GAAG,IAAI,OAAO,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,EAAE,IAAI,GAAG,IAAI,KAAK,CAAC;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAEvC,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC5B,CAAC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,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACvC,CAAC;CACF;AAhND,4BAgNC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MorphTo Relationship
|
|
3
|
+
*
|
|
4
|
+
* Represents a polymorphic inverse relationship
|
|
5
|
+
* Example: Comment belongs to Post or Video (commentable)
|
|
6
|
+
*/
|
|
7
|
+
import { Ensemble } from '../Ensemble';
|
|
8
|
+
import { EnsembleBuilder } from '../EnsembleBuilder';
|
|
9
|
+
import { EnsembleCollection } from '../EnsembleCollection';
|
|
10
|
+
import { Relation } from './Relation';
|
|
11
|
+
export declare class MorphTo<TParent extends Ensemble> extends Relation<Ensemble, TParent> {
|
|
12
|
+
/**
|
|
13
|
+
* The foreign key of the parent model (e.g., 'commentable_id')
|
|
14
|
+
*/
|
|
15
|
+
protected foreignKey: string;
|
|
16
|
+
/**
|
|
17
|
+
* The morph type column (e.g., 'commentable_type')
|
|
18
|
+
*/
|
|
19
|
+
protected morphType: string;
|
|
20
|
+
/**
|
|
21
|
+
* The owner key on the related model
|
|
22
|
+
*/
|
|
23
|
+
protected ownerKey: string;
|
|
24
|
+
/**
|
|
25
|
+
* The name of the relationship
|
|
26
|
+
*/
|
|
27
|
+
protected relationName: string;
|
|
28
|
+
/**
|
|
29
|
+
* Dictionary of models grouped by type
|
|
30
|
+
*/
|
|
31
|
+
protected dictionary: Map<string, Map<any, Ensemble>>;
|
|
32
|
+
/**
|
|
33
|
+
* Models loaded by type
|
|
34
|
+
*/
|
|
35
|
+
protected models: Map<string, Ensemble[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Create a new morph to relationship instance
|
|
38
|
+
*/
|
|
39
|
+
constructor(query: EnsembleBuilder<Ensemble>, parent: TParent, foreignKey: string, morphType: string, ownerKey: string, relationName: string);
|
|
40
|
+
/**
|
|
41
|
+
* Set the base constraints on the relation query
|
|
42
|
+
* MorphTo doesn't use base constraints - queries are built per type
|
|
43
|
+
*/
|
|
44
|
+
addConstraints(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Set the constraints for an eager load of the relation
|
|
47
|
+
*/
|
|
48
|
+
addEagerConstraints(models: TParent[]): void;
|
|
49
|
+
/**
|
|
50
|
+
* Build dictionary of models grouped by morph type
|
|
51
|
+
*/
|
|
52
|
+
protected buildDictionary(models: TParent[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Initialize the relation on a set of models
|
|
55
|
+
*/
|
|
56
|
+
initRelation(models: TParent[], relation: string): TParent[];
|
|
57
|
+
/**
|
|
58
|
+
* Match the eagerly loaded results to their parents
|
|
59
|
+
*/
|
|
60
|
+
match(models: TParent[], results: EnsembleCollection<Ensemble>, relation: string): TParent[];
|
|
61
|
+
/**
|
|
62
|
+
* Get the eager loading results
|
|
63
|
+
*/
|
|
64
|
+
getEager(): Promise<Ensemble[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get the results of the relationship
|
|
67
|
+
*/
|
|
68
|
+
getResults(): Promise<Ensemble | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Associate the model instance to the parent model
|
|
71
|
+
*/
|
|
72
|
+
associate(model: Ensemble | null): this;
|
|
73
|
+
/**
|
|
74
|
+
* Dissociate the model from the parent
|
|
75
|
+
*/
|
|
76
|
+
dissociate(): this;
|
|
77
|
+
/**
|
|
78
|
+
* Get the foreign key value
|
|
79
|
+
*/
|
|
80
|
+
protected getForeignKeyValue(): any;
|
|
81
|
+
/**
|
|
82
|
+
* Get the morph type value
|
|
83
|
+
*/
|
|
84
|
+
protected getMorphTypeValue(): string | null;
|
|
85
|
+
/**
|
|
86
|
+
* Get the foreign key for the relationship
|
|
87
|
+
*/
|
|
88
|
+
getForeignKeyName(): string;
|
|
89
|
+
/**
|
|
90
|
+
* Get the morph type for the relationship
|
|
91
|
+
*/
|
|
92
|
+
getMorphType(): string;
|
|
93
|
+
/**
|
|
94
|
+
* Get the owner key for the relationship
|
|
95
|
+
*/
|
|
96
|
+
getOwnerKeyName(): string;
|
|
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S,CAAC,eAAe,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI;IAoBlD;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE;IAQ5D;;OAEG;IACH,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,EAAE;IAuB5F;;OAEG;IACG,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAgCrC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAsB5C;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,IAAI;IAYvC;;OAEG;IACH,UAAU,IAAI,IAAI;IAQlB;;OAEG;IACH,SAAS,CAAC,kBAAkB,IAAI,GAAG;IAInC;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI,MAAM,GAAG,IAAI;IAI5C;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAI3B;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,eAAe,IAAI,MAAM;CAG1B"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MorphTo Relationship
|
|
4
|
+
*
|
|
5
|
+
* Represents a polymorphic inverse relationship
|
|
6
|
+
* Example: Comment belongs to Post or Video (commentable)
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MorphTo = void 0;
|
|
10
|
+
const Relation_1 = require("./Relation");
|
|
11
|
+
const MorphMap_1 = require("./MorphMap");
|
|
12
|
+
class MorphTo extends Relation_1.Relation {
|
|
13
|
+
/**
|
|
14
|
+
* The foreign key of the parent model (e.g., 'commentable_id')
|
|
15
|
+
*/
|
|
16
|
+
foreignKey;
|
|
17
|
+
/**
|
|
18
|
+
* The morph type column (e.g., 'commentable_type')
|
|
19
|
+
*/
|
|
20
|
+
morphType;
|
|
21
|
+
/**
|
|
22
|
+
* The owner key on the related model
|
|
23
|
+
*/
|
|
24
|
+
ownerKey;
|
|
25
|
+
/**
|
|
26
|
+
* The name of the relationship
|
|
27
|
+
*/
|
|
28
|
+
relationName;
|
|
29
|
+
/**
|
|
30
|
+
* Dictionary of models grouped by type
|
|
31
|
+
*/
|
|
32
|
+
dictionary = new Map();
|
|
33
|
+
/**
|
|
34
|
+
* Models loaded by type
|
|
35
|
+
*/
|
|
36
|
+
models = new Map();
|
|
37
|
+
/**
|
|
38
|
+
* Create a new morph to relationship instance
|
|
39
|
+
*/
|
|
40
|
+
constructor(query, parent, foreignKey, morphType, ownerKey, relationName) {
|
|
41
|
+
super(query, parent);
|
|
42
|
+
this.foreignKey = foreignKey;
|
|
43
|
+
this.morphType = morphType;
|
|
44
|
+
this.ownerKey = ownerKey;
|
|
45
|
+
this.relationName = relationName;
|
|
46
|
+
// Don't call initializeRelation() - MorphTo doesn't add constraints in constructor
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Set the base constraints on the relation query
|
|
50
|
+
* MorphTo doesn't use base constraints - queries are built per type
|
|
51
|
+
*/
|
|
52
|
+
addConstraints() {
|
|
53
|
+
// MorphTo doesn't add constraints here
|
|
54
|
+
// Constraints are added dynamically based on type
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Set the constraints for an eager load of the relation
|
|
58
|
+
*/
|
|
59
|
+
addEagerConstraints(models) {
|
|
60
|
+
// Build dictionary grouped by type
|
|
61
|
+
this.buildDictionary(models);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Build dictionary of models grouped by morph type
|
|
65
|
+
*/
|
|
66
|
+
buildDictionary(models) {
|
|
67
|
+
this.dictionary.clear();
|
|
68
|
+
for (const model of models) {
|
|
69
|
+
const type = model.getAttribute(this.morphType);
|
|
70
|
+
const id = model.getAttribute(this.foreignKey);
|
|
71
|
+
if (!type || (id === null || id === undefined)) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (!this.dictionary.has(type)) {
|
|
75
|
+
this.dictionary.set(type, new Map());
|
|
76
|
+
}
|
|
77
|
+
const typeDict = this.dictionary.get(type);
|
|
78
|
+
typeDict.set(id, null); // Placeholder, will be replaced in match
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Initialize the relation on a set of models
|
|
83
|
+
*/
|
|
84
|
+
initRelation(models, relation) {
|
|
85
|
+
for (const model of models) {
|
|
86
|
+
model.setRelation(relation, null);
|
|
87
|
+
}
|
|
88
|
+
return models;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Match the eagerly loaded results to their parents
|
|
92
|
+
*/
|
|
93
|
+
match(models, results, relation) {
|
|
94
|
+
// Match each model with its related parent
|
|
95
|
+
for (const model of models) {
|
|
96
|
+
const type = model.getAttribute(this.morphType);
|
|
97
|
+
const id = model.getAttribute(this.foreignKey);
|
|
98
|
+
if (!type || (id === null || id === undefined)) {
|
|
99
|
+
model.setRelation(relation, null);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const typeDict = this.dictionary.get(type);
|
|
103
|
+
if (typeDict && typeDict.has(id)) {
|
|
104
|
+
const related = typeDict.get(id);
|
|
105
|
+
model.setRelation(relation, related || null);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
model.setRelation(relation, null);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return models;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get the eager loading results
|
|
115
|
+
*/
|
|
116
|
+
async getEager() {
|
|
117
|
+
const allResults = [];
|
|
118
|
+
for (const [type, ids] of this.dictionary.entries()) {
|
|
119
|
+
const modelClass = MorphMap_1.MorphMap.getClass(type);
|
|
120
|
+
if (!modelClass) {
|
|
121
|
+
console.warn(`MorphTo: Unknown morph type "${type}". Did you forget to register it in MorphMap?`);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const instance = new modelClass();
|
|
125
|
+
const models = await instance
|
|
126
|
+
.newQuery()
|
|
127
|
+
.whereIn(this.ownerKey, Array.from(ids.keys()))
|
|
128
|
+
.get();
|
|
129
|
+
// Store in dictionary for matching
|
|
130
|
+
for (const model of models) {
|
|
131
|
+
const key = model.getAttribute(this.ownerKey);
|
|
132
|
+
const typeDict = this.dictionary.get(type);
|
|
133
|
+
if (typeDict && typeDict.has(key)) {
|
|
134
|
+
typeDict.set(key, model);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
allResults.push(...models);
|
|
138
|
+
}
|
|
139
|
+
return allResults;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Get the results of the relationship
|
|
143
|
+
*/
|
|
144
|
+
async getResults() {
|
|
145
|
+
const type = this.parent.getAttribute(this.morphType);
|
|
146
|
+
const id = this.parent.getAttribute(this.foreignKey);
|
|
147
|
+
if (!type || (id === null || id === undefined)) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
const modelClass = MorphMap_1.MorphMap.getClass(type);
|
|
151
|
+
if (!modelClass) {
|
|
152
|
+
console.warn(`MorphTo: Unknown morph type "${type}". Did you forget to register it in MorphMap?`);
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const instance = new modelClass();
|
|
156
|
+
return instance
|
|
157
|
+
.newQuery()
|
|
158
|
+
.where(this.ownerKey, '=', id)
|
|
159
|
+
.first();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Associate the model instance to the parent model
|
|
163
|
+
*/
|
|
164
|
+
associate(model) {
|
|
165
|
+
if (model === null) {
|
|
166
|
+
return this.dissociate();
|
|
167
|
+
}
|
|
168
|
+
this.parent.setAttribute(this.foreignKey, model.getAttribute(this.ownerKey));
|
|
169
|
+
this.parent.setAttribute(this.morphType, MorphMap_1.MorphMap.getMorphedModel(model));
|
|
170
|
+
this.parent.setRelation(this.relationName, model);
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Dissociate the model from the parent
|
|
175
|
+
*/
|
|
176
|
+
dissociate() {
|
|
177
|
+
this.parent.setAttribute(this.foreignKey, null);
|
|
178
|
+
this.parent.setAttribute(this.morphType, null);
|
|
179
|
+
this.parent.setRelation(this.relationName, null);
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get the foreign key value
|
|
184
|
+
*/
|
|
185
|
+
getForeignKeyValue() {
|
|
186
|
+
return this.parent.getAttribute(this.foreignKey);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get the morph type value
|
|
190
|
+
*/
|
|
191
|
+
getMorphTypeValue() {
|
|
192
|
+
return this.parent.getAttribute(this.morphType);
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Get the foreign key for the relationship
|
|
196
|
+
*/
|
|
197
|
+
getForeignKeyName() {
|
|
198
|
+
return this.foreignKey;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get the morph type for the relationship
|
|
202
|
+
*/
|
|
203
|
+
getMorphType() {
|
|
204
|
+
return this.morphType;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get the owner key for the relationship
|
|
208
|
+
*/
|
|
209
|
+
getOwnerKeyName() {
|
|
210
|
+
return this.ownerKey;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
exports.MorphTo = MorphTo;
|
|
214
|
+
//# sourceMappingURL=MorphTo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MorphTo.js","sourceRoot":"","sources":["../../../../src/Database/Ensemble/Relations/MorphTo.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAKH,yCAAsC;AACtC,yCAAsC;AAEtC,MAAa,OAAkC,SAAQ,mBAA2B;I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,EAAE,KAAK,CAAC,CAAC;QAElD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,UAAU;QACR,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QAEjD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACO,kBAAkB;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACO,iBAAiB;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAvPD,0BAuPC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MorphToMany Relationship
|
|
3
|
+
*
|
|
4
|
+
* Represents a polymorphic many-to-many relationship from the parent side
|
|
5
|
+
* Example: Post has many Tags (where Tag can belong to many types via taggables table)
|
|
6
|
+
*/
|
|
7
|
+
import { Ensemble } from '../Ensemble';
|
|
8
|
+
import { EnsembleBuilder } from '../EnsembleBuilder';
|
|
9
|
+
import { BelongsToMany } from './BelongsToMany';
|
|
10
|
+
export declare class MorphToMany<TRelated extends Ensemble, TParent extends Ensemble> extends BelongsToMany<TRelated, TParent> {
|
|
11
|
+
/**
|
|
12
|
+
* The morph type column (e.g., 'taggable_type')
|
|
13
|
+
*/
|
|
14
|
+
protected morphType: string;
|
|
15
|
+
/**
|
|
16
|
+
* The morph class name or alias
|
|
17
|
+
*/
|
|
18
|
+
protected morphClass: string;
|
|
19
|
+
/**
|
|
20
|
+
* Whether this is the inverse of the relation
|
|
21
|
+
*/
|
|
22
|
+
protected inverse: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Create a new morph to many relationship instance
|
|
25
|
+
*/
|
|
26
|
+
constructor(query: EnsembleBuilder<TRelated>, parent: TParent, name: string, table: string, foreignPivotKey: string, relatedPivotKey: string, morphType: string, parentKey: string, relatedKey: string, relationName?: string, inverse?: boolean);
|
|
27
|
+
/**
|
|
28
|
+
* Set the join clause for the relation query
|
|
29
|
+
* Adds the morph type constraint
|
|
30
|
+
*/
|
|
31
|
+
protected performJoin(query?: EnsembleBuilder<TRelated>): void;
|
|
32
|
+
/**
|
|
33
|
+
* Set the where clause for eager loading
|
|
34
|
+
*/
|
|
35
|
+
protected addWhereConstraints(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Get the morph class for the parent during initialization
|
|
38
|
+
*/
|
|
39
|
+
protected getMorphClass(): string;
|
|
40
|
+
/**
|
|
41
|
+
* Get the morph type name
|
|
42
|
+
*/
|
|
43
|
+
getMorphType(): string;
|
|
44
|
+
/**
|
|
45
|
+
* Get the morph class value
|
|
46
|
+
*/
|
|
47
|
+
getMorphClassValue(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Set the morph class (used for inverse relations)
|
|
50
|
+
*/
|
|
51
|
+
setMorphClass(morphClass: string): this;
|
|
52
|
+
/**
|
|
53
|
+
* Attach models to the parent with morph type
|
|
54
|
+
*/
|
|
55
|
+
attach(ids: any | any[], attributes?: Record<string, any>, touch?: boolean): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Detach models from the parent with morph type constraint
|
|
58
|
+
*/
|
|
59
|
+
detach(ids?: any | any[]): Promise<number>;
|
|
60
|
+
/**
|
|
61
|
+
* Sync the intermediate tables with morph type
|
|
62
|
+
*/
|
|
63
|
+
sync(ids: any[], detaching?: boolean): Promise<{
|
|
64
|
+
attached: any[];
|
|
65
|
+
detached: any[];
|
|
66
|
+
updated: any[];
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Create a new pivot query
|
|
70
|
+
*/
|
|
71
|
+
protected newPivotQuery(): EnsembleBuilder<any>;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=MorphToMany.d.ts.map
|