loopback-softdelete-mixin icon indicating copy to clipboard operation
loopback-softdelete-mixin copied to clipboard

Strange incompatibility

Open alemhnan opened this issue 9 years ago • 7 comments

Still me unfortunately! I have a clean generated project in loopback and just added the softdelete-mixin. I am using node v5.2.0. If I included the mixin in model-config.json I got this error:

./node_modules/loopback-swagger/lib/specgen/schema-builder.js:149
    if (key in ldlDef) {
               ^

TypeError: Cannot use 'in' operator to search for 'min' in true

I tried to run also npm install inside the npm package but I got the same result. Honestly I have no idea what's going on. I will try to dig up more. If you have any suggestions let me know!

alemhnan avatar Dec 11 '15 16:12 alemhnan

huh so ldlDef is "true" for some reason. Weird. I'll take a look into it also, but not able to probably until tomorrow now.

gausie avatar Dec 11 '15 16:12 gausie

Hi, having the same issue with a fresh project - i'll try to help diagnose this. It is really what i've been looking for. I was about to just recreate it myself.

beezenees avatar Dec 21 '15 04:12 beezenees

Changing the

    Model.defineProperty(_isDeleted, {
        required: true,
        'default': false
    });

to:

    Model.defineProperty(_isDeleted, {
        required: true,
        type: Boolean,
        'default': false
    });

fixed it for me.

beezenees avatar Dec 21 '15 04:12 beezenees

There is a reason I removed the type from this which I will type up for general consumption later and add it to the README. Unfortunately, some bugs/lacking features in loopback / loopback-datasource-juggler make this mixin awkward.

Essentially when you make it a Boolean, you can't check if the property exists or not because when you run a query like { _isDeleted: { exists: true } } it tries to coerce the object { exists: true } to a Boolean and fails.

gausie avatar Dec 21 '15 10:12 gausie

Ok, that makes sense :/ I was not able to get the mixin to work fully, even with the changing of the type. All that did was remove the error. I will have to try and explore a different method of doing this.

beezenees avatar Dec 21 '15 15:12 beezenees

@gausie any update about this issue?

amrnt avatar Jan 21 '16 10:01 amrnt

Seems to be related to this issue in loopback-swagger, which was merged to master about 9 days ago. I added this line to my package.json dependences

"loopback-swagger": "git://github.com/strongloop/loopback-swagger.git#6d13c8c75978e88ed31c0921765f0b6959f36fdb" which references a commit from a few days ago that includes this change.

Additionally and unrelated, once that was solved I had to change line 113 and 130 to be compatible for the SQLite connector; I'm unsure if it would work in other RDBMS, but the SQL ends up and-ing an empty brackets to the delete clause. SQLite doesn't interpret empty brackets as truthy. So I just made it a condition that will (normally) be true. Wasn't sure how to get the query writer to let me just do "1=1"

if (!query.where) query.where = {id: {gt: -100000}};

cmoore4 avatar Jan 29 '16 05:01 cmoore4