dobo 2.11.3 → 2.11.4
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/factory/model/_util.js +46 -42
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
|
@@ -171,23 +171,25 @@ export async function getSingleRef (record = {}, options = {}) {
|
|
|
171
171
|
if (props.length > 0) {
|
|
172
172
|
for (const prop of props) {
|
|
173
173
|
for (const key in prop.ref) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
174
|
+
try {
|
|
175
|
+
if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
|
|
176
|
+
const ref = prop.ref[key]
|
|
177
|
+
if (ref.fields.length === 0) continue
|
|
178
|
+
if (get(record, `_ref.${key}`)) continue
|
|
179
|
+
const rModel = this.app.dobo.getModel(ref.model)
|
|
180
|
+
const query = {}
|
|
181
|
+
query[ref.propName] = record[prop.name]
|
|
182
|
+
if (ref.propName === 'id') query[ref.propName] = this.sanitizeId(query[ref.propName])
|
|
183
|
+
const rFilter = { query }
|
|
184
|
+
const rOptions = { dataOnly: true, refs: [] }
|
|
185
|
+
const results = await rModel.findRecord(rFilter, rOptions)
|
|
186
|
+
const fields = [...ref.fields]
|
|
187
|
+
const data = []
|
|
188
|
+
for (const res of results) {
|
|
189
|
+
data.push(await rModel.sanitizeRecord(res, { fields }))
|
|
190
|
+
}
|
|
191
|
+
refs[key] = ['1:1'].includes(ref.type) ? data[0] : data
|
|
192
|
+
} catch (err) {}
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
}
|
|
@@ -202,31 +204,33 @@ export async function getMultiRefs (records = [], options = {}) {
|
|
|
202
204
|
if (props.length > 0) {
|
|
203
205
|
for (const prop of props) {
|
|
204
206
|
for (const key in prop.ref) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
207
|
+
try {
|
|
208
|
+
if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
|
|
209
|
+
const ref = prop.ref[key]
|
|
210
|
+
if (ref.fields.length === 0) continue
|
|
211
|
+
if (ref.type !== '1:1') continue
|
|
212
|
+
if (get(records, `0._ref.${key}`)) continue
|
|
213
|
+
const rModel = this.app.dobo.getModel(ref.model)
|
|
214
|
+
let matches = []
|
|
215
|
+
for (const r of records) {
|
|
216
|
+
matches.push(rModel.sanitizeId(r[prop.name]))
|
|
217
|
+
}
|
|
218
|
+
matches = uniq(without(matches, undefined, null, NaN))
|
|
219
|
+
const query = {}
|
|
220
|
+
query[ref.propName] = { $in: matches }
|
|
221
|
+
const rFilter = { query, limit: matches.length }
|
|
222
|
+
const rOptions = { dataOnly: true, refs: [] }
|
|
223
|
+
const results = await rModel.findRecord(rFilter, rOptions)
|
|
224
|
+
const fields = [...ref.fields]
|
|
225
|
+
if (!fields.includes(prop.name)) fields.push(prop.name)
|
|
226
|
+
for (const i in records) {
|
|
227
|
+
records[i]._ref = records[i]._ref ?? {}
|
|
228
|
+
const rec = records[i]
|
|
229
|
+
const res = results.find(res => (res[ref.propName] + '') === rec[prop.name] + '')
|
|
230
|
+
if (res) records[i]._ref[key] = await rModel.sanitizeRecord(res, { fields })
|
|
231
|
+
else records[i]._ref[key] = {}
|
|
232
|
+
}
|
|
233
|
+
} catch (err) {}
|
|
230
234
|
}
|
|
231
235
|
}
|
|
232
236
|
}
|
package/package.json
CHANGED