orange-dragonfly-model 0.11.3 → 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.
@@ -80,11 +80,12 @@ class Model extends ORM.ActiveRecord {
80
80
  /**
81
81
  * Lookup method
82
82
  * @param data
83
+ * @param {?FilteredQuery} basicQuery Query to be used for adding conditions automatically. By default new SelectQuery object will be created.
83
84
  * @return {SelectQuery}
84
85
  */
85
- static lookupQuery (data) {
86
+ static lookupQuery (data, basicQuery = null) {
86
87
  const rules = this.validation_rules
87
- const q = this.selectQuery()
88
+ const q = basicQuery || this.selectQuery()
88
89
  const filtered_rules = {}
89
90
  for (const field of Object.keys(data)) {
90
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.3",
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 }