dobo 2.3.0 → 2.3.1
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/lib/collect-models.js +7 -5
- package/lib/factory/model/_util.js +7 -6
- package/package.json +1 -1
- package/wiki/CHANGES.md +5 -0
package/lib/collect-models.js
CHANGED
|
@@ -126,7 +126,7 @@ async function findAllIndexes (model, inputs = []) {
|
|
|
126
126
|
* @param {Object} model - Model
|
|
127
127
|
* @param {Array} [models] - All model match agaist. Defaults to ```dobo.models```
|
|
128
128
|
*/
|
|
129
|
-
export async function sanitizeRef (model, models
|
|
129
|
+
export async function sanitizeRef (model, models) {
|
|
130
130
|
const { find, isString, pullAt } = this.app.lib._
|
|
131
131
|
if (!models) models = this.models
|
|
132
132
|
for (const prop of model.properties) {
|
|
@@ -139,13 +139,15 @@ export async function sanitizeRef (model, models, fatal) {
|
|
|
139
139
|
ref.type = ref.type ?? '1:1'
|
|
140
140
|
const rModel = find(models, { name: ref.model })
|
|
141
141
|
if (!rModel) {
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
ignored.push(key)
|
|
143
|
+
this.log.warn('notFound%s%s', this.t('model'), ref.model)
|
|
144
|
+
continue
|
|
144
145
|
}
|
|
145
146
|
const rProp = find(rModel.properties, { name: ref.propName })
|
|
146
147
|
if (!rProp) {
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
ignored.push(key)
|
|
149
|
+
this.log.warn('notFound%s%s', this.t('property'), `${ref.propName}@${ref.model}`)
|
|
150
|
+
continue
|
|
149
151
|
}
|
|
150
152
|
ref.fields = ref.fields ?? '*'
|
|
151
153
|
if (['*', 'all'].includes(ref.fields)) ref.fields = rModel.properties.map(p => p.name)
|
|
@@ -189,7 +189,7 @@ export async function getSingleRef (record = {}, options = {}) {
|
|
|
189
189
|
|
|
190
190
|
export async function getMultiRefs (records = [], options = {}) {
|
|
191
191
|
const { isSet } = this.app.lib.aneka
|
|
192
|
-
const { uniq,
|
|
192
|
+
const { uniq, without, get } = this.app.lib._
|
|
193
193
|
const props = this.properties.filter(p => isSet(p.ref) && !(options.hidden ?? []).includes(p.name))
|
|
194
194
|
options.refs = options.refs ?? []
|
|
195
195
|
if (props.length > 0) {
|
|
@@ -201,15 +201,16 @@ export async function getMultiRefs (records = [], options = {}) {
|
|
|
201
201
|
if (ref.type !== '1:1') continue
|
|
202
202
|
if (get(records, `0._ref.${key}`)) continue
|
|
203
203
|
const rModel = this.app.dobo.getModel(ref.model)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
204
|
+
let matches = []
|
|
205
|
+
for (const r of records) {
|
|
206
|
+
matches.push(rModel.sanitizeId(r[prop.name]))
|
|
207
|
+
}
|
|
208
|
+
matches = uniq(without(matches, undefined, null, NaN))
|
|
209
209
|
const query = {}
|
|
210
210
|
query[ref.propName] = { $in: matches }
|
|
211
211
|
const rFilter = { query, limit: matches.length }
|
|
212
212
|
const rOptions = { dataOnly: true, refs: [] }
|
|
213
|
+
this.app.dump(this.name, rModel.name, rFilter, records)
|
|
213
214
|
const results = await rModel.findRecord(rFilter, rOptions)
|
|
214
215
|
const fields = [...ref.fields]
|
|
215
216
|
if (!fields.includes(prop.name)) fields.push(prop.name)
|
package/package.json
CHANGED