orange-dragonfly-model 0.11.2 → 0.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.
@@ -2,9 +2,7 @@ const ORM = require('orange-dragonfly-orm')
2
2
  const validate = require('orange-dragonfly-validator')
3
3
 
4
4
  class ValidationException extends Error {
5
- get info () {
6
- return {}
7
- }
5
+ info = {}
8
6
  }
9
7
 
10
8
  class Model extends ORM.ActiveRecord {
@@ -82,11 +80,12 @@ class Model extends ORM.ActiveRecord {
82
80
  /**
83
81
  * Lookup method
84
82
  * @param data
83
+ * @param {?FilteredQuery} basicQuery Query to be used for adding conditions automatically. By default new SelectQuery object will be created.
85
84
  * @return {SelectQuery}
86
85
  */
87
- static lookupQuery (data) {
86
+ static lookupQuery (data, basicQuery = null) {
88
87
  const rules = this.validation_rules
89
- const q = this.selectQuery()
88
+ const q = basicQuery || this.selectQuery()
90
89
  const filtered_rules = {}
91
90
  for (const field of Object.keys(data)) {
92
91
  if (!rules.hasOwnProperty(field)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orange-dragonfly-model",
3
- "version": "0.11.2",
3
+ "version": "0.11.4",
4
4
  "description": "Orange Dragonfly Model",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -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 }