orange-dragonfly-model 0.11.3 → 0.11.5
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/components/model.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
const { ActiveRecord } = require('orange-dragonfly-orm')
|
|
2
2
|
const validate = require('orange-dragonfly-validator')
|
|
3
|
+
const ValidationException = require('./validation-exception')
|
|
3
4
|
|
|
4
|
-
class
|
|
5
|
-
info = {}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class Model extends ORM.ActiveRecord {
|
|
5
|
+
class Model extends ActiveRecord {
|
|
9
6
|
static get IGNORE_EXTRA_FIELDS () {
|
|
10
7
|
return false
|
|
11
8
|
}
|
|
@@ -18,6 +15,14 @@ class Model extends ORM.ActiveRecord {
|
|
|
18
15
|
return []
|
|
19
16
|
}
|
|
20
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Returns list of fulltext keys
|
|
20
|
+
* @returns Array[] List of unique keys
|
|
21
|
+
*/
|
|
22
|
+
static get FULLTEXT_INDEXES () {
|
|
23
|
+
return []
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* Returns schema for the model (Orange Dragonfly Validator format)
|
|
23
28
|
* @return object
|
|
@@ -80,11 +85,12 @@ class Model extends ORM.ActiveRecord {
|
|
|
80
85
|
/**
|
|
81
86
|
* Lookup method
|
|
82
87
|
* @param data
|
|
88
|
+
* @param {?FilteredQuery} basicQuery Query to be used for adding conditions automatically. By default new SelectQuery object will be created.
|
|
83
89
|
* @return {SelectQuery}
|
|
84
90
|
*/
|
|
85
|
-
static lookupQuery (data) {
|
|
91
|
+
static lookupQuery (data, basicQuery = null) {
|
|
86
92
|
const rules = this.validation_rules
|
|
87
|
-
const q = this.selectQuery()
|
|
93
|
+
const q = basicQuery || this.selectQuery()
|
|
88
94
|
const filtered_rules = {}
|
|
89
95
|
for (const field of Object.keys(data)) {
|
|
90
96
|
if (!rules.hasOwnProperty(field)) {
|
package/package.json
CHANGED
|
@@ -10,6 +10,14 @@ test('select-id', () => {
|
|
|
10
10
|
expect(q.params).toEqual(data)
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
+
test('delete-id', () => {
|
|
14
|
+
const data = [1]
|
|
15
|
+
const lookup_data = { id: data[0] }
|
|
16
|
+
const q = TestModel.lookupQuery(lookup_data, TestModel.deleteQuery()).buildRawSQL()
|
|
17
|
+
expect(q.sql).toBe('DELETE FROM test_model WHERE test_model.id = ?')
|
|
18
|
+
expect(q.params).toEqual(data)
|
|
19
|
+
})
|
|
20
|
+
|
|
13
21
|
test('select-id-multiple', () => {
|
|
14
22
|
const data = [1, 2, 3]
|
|
15
23
|
const lookup_data = { id: data }
|