@kaspernj/api-maker 1.0.269 → 1.0.271
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/package.json +1 -1
- package/src/base-model.mjs +18 -0
- package/src/collection.mjs +14 -5
package/package.json
CHANGED
package/src/base-model.mjs
CHANGED
|
@@ -143,6 +143,16 @@ export default class BaseModel {
|
|
|
143
143
|
return reflections
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
+
static reflection(name) {
|
|
147
|
+
const foundReflection = this.reflections().find((reflection) => reflection.name() == name)
|
|
148
|
+
|
|
149
|
+
if (!foundReflection) {
|
|
150
|
+
throw new Error(`No such reflection: ${name} in ${this.reflections().map((reflection) => reflection.name()).join(", ")}`)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return foundReflection
|
|
154
|
+
}
|
|
155
|
+
|
|
146
156
|
constructor (args = {}) {
|
|
147
157
|
this.changes = {}
|
|
148
158
|
this.newRecord = args.isNewRecord
|
|
@@ -717,6 +727,14 @@ export default class BaseModel {
|
|
|
717
727
|
this.relationships[BaseModel.snakeCase(relationshipName)] = model
|
|
718
728
|
}
|
|
719
729
|
|
|
730
|
+
markForDestruction() {
|
|
731
|
+
this._markedForDestruction = true
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
markedForDestruction() {
|
|
735
|
+
return this._markedForDestruction
|
|
736
|
+
}
|
|
737
|
+
|
|
720
738
|
uniqueKey () {
|
|
721
739
|
if (!this.uniqueKeyValue) {
|
|
722
740
|
const min = 5000000000000000
|
package/src/collection.mjs
CHANGED
|
@@ -96,12 +96,21 @@ export default class ApiMakerCollection {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
loaded () {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
99
|
+
const {model, reflectionName} = this.args
|
|
100
|
+
|
|
101
|
+
if (reflectionName in model.relationships) {
|
|
102
|
+
return model.relationships[reflectionName]
|
|
103
|
+
} else if (reflectionName in model.relationshipsCache) {
|
|
104
|
+
return model.relationshipsCache[reflectionName]
|
|
105
|
+
} else if (model.isNewRecord()) {
|
|
106
|
+
const reflectionNameUnderscore = inflection.underscore(reflectionName)
|
|
107
|
+
|
|
108
|
+
// Initialize as empty and try again to return the empty result
|
|
109
|
+
this.set([])
|
|
110
|
+
|
|
111
|
+
return digg(model.relationships, reflectionNameUnderscore)
|
|
103
112
|
} else {
|
|
104
|
-
throw new Error(`${
|
|
113
|
+
throw new Error(`${reflectionName} hasnt been loaded yet`)
|
|
105
114
|
}
|
|
106
115
|
}
|
|
107
116
|
|