kylefarris / node-querybuilder

Node QueryBuilder Adapter for Node.js (tags: nodejs, node, mysql, active record, activerecord, querybuilder, query builder)
49 stars 19 forks source link

Deleting using 'where object' with array value ignores other properties #28

Closed Flamenco closed 6 years ago

Flamenco commented 6 years ago

Expected behavior All properties should use 'AND'

qb.delete('tags', {songId: [300], tagName: oldTag}, (err, res) => {})

This query results in

DELETE FROM `tags` WHERE `songId` IN (300)

Workaround: Re-add ignored fields.

qb.where({tagName: oldTag}).delete('tags', {songId: [300], tagName: oldTag}, (err, res) => {})

This query results in

DELETE FROM `tags` WHERE `tagName` = 'test1' AND `songId` IN (300)

This applies to at least this 'delete use-case', if not more.

kylefarris commented 6 years ago

Interesting edge case. I'll write a test and add it to the v2 release.

Flamenco commented 6 years ago

@kylefarris My example is a pruned down version that isolates the issue. My actual query had hundreds of items in the array.

kylefarris commented 6 years ago

@Flamenco Oh, I'm sure. Looks like a totally valid issue, I just never thought of that particular case when writing the tests. I'm deep into writing version 2 of the module. The fix for this will be in that release. I'm hoping to have it out in the next few weeks or so. I'm glad you have workaround for now.

Thanks for your bug report and input!

kylefarris commented 6 years ago

This is officially fixed in the v2 branch. Beta should be out soon.