dobo 1.1.12 → 1.1.13

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.
@@ -1,8 +1,8 @@
1
1
  async function multiRelRows ({ schema, records, options = {} }) {
2
2
  const { isSet } = this.app.bajo
3
+ const { uniq, find, map } = this.lib._
3
4
  const props = schema.properties.filter(p => isSet(p.rel) && !(options.hidden ?? []).includes(p.name))
4
5
  // const props = schema.properties.filter(p => isSet(p.rel))
5
- const rels = {}
6
6
  options.rels = options.rels ?? []
7
7
  if (props.length > 0) {
8
8
  for (const prop of props) {
@@ -11,8 +11,15 @@ async function multiRelRows ({ schema, records, options = {} }) {
11
11
  const val = prop.rel[key]
12
12
  if (val.fields.length === 0) continue
13
13
  if (val.type !== 'one-to-one') continue
14
- const matches = records.map(r => r[prop.name])
15
14
  const relschema = this.getSchema(val.schema)
15
+ const matches = uniq(map(records, r => {
16
+ let v = r[prop.name]
17
+ if (val.propName === 'id') {
18
+ const idField = find(relschema.properties, { name: 'id' })
19
+ if (idField.type === 'integer') v = parseInt(v)
20
+ }
21
+ return v
22
+ }))
16
23
  const query = {}
17
24
  query[val.propName] = { $in: matches }
18
25
  const relFilter = { query, limit: matches.length }
@@ -23,13 +30,13 @@ async function multiRelRows ({ schema, records, options = {} }) {
23
30
  for (const i in records) {
24
31
  records[i]._rel = records[i]._rel ?? {}
25
32
  const rec = records[i]
26
- const res = results.find(r => r[val.propName] === rec[prop.name])
33
+ const res = results.find(r => (r[val.propName] + '') === rec[prop.name])
27
34
  if (res) records[i]._rel[key] = await this.pickRecord({ record: res, fields, schema: relschema })
35
+ else records[i]._rel[key] = {}
28
36
  }
29
37
  }
30
38
  }
31
39
  }
32
- return rels
33
40
  }
34
41
 
35
42
  export default multiRelRows
@@ -1,5 +1,6 @@
1
1
  async function singleRelRows ({ schema, record, options = {} }) {
2
2
  const { isSet } = this.app.bajo
3
+ const { find } = this.lib._
3
4
  const props = schema.properties.filter(p => isSet(p.rel) && !(options.hidden ?? []).includes(p.name))
4
5
  const rels = {}
5
6
  options.rels = options.rels ?? []
@@ -13,6 +14,11 @@ async function singleRelRows ({ schema, record, options = {} }) {
13
14
  const relFilter = options.filter ?? {}
14
15
  const query = {}
15
16
  query[val.propName] = record[prop.name]
17
+ if (val.propName === 'id') {
18
+ const idField = find(relschema.properties, { name: 'id' })
19
+ if (idField.type === 'integer') query[val.propName] = parseInt(query[val.propName])
20
+ }
21
+
16
22
  relFilter.query = query
17
23
  const relOptions = { dataOnly: true, rels: [] }
18
24
  const results = await this.recordFind(relschema.name, relFilter, relOptions)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {