Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange incompatibility #2

Open
alemhnan opened this issue Dec 11, 2015 · 7 comments
Open

Strange incompatibility #2

alemhnan opened this issue Dec 11, 2015 · 7 comments

Comments

@alemhnan
Copy link

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!

@gausie
Copy link
Owner

gausie commented Dec 11, 2015

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.

@beezenees
Copy link

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
Copy link

Changing the

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

to:

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

fixed it for me.

@gausie
Copy link
Owner

gausie commented Dec 21, 2015

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.

@beezenees
Copy link

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.

@amrnt
Copy link

amrnt commented Jan 21, 2016

@gausie any update about this issue?

@cmoore4
Copy link

cmoore4 commented Jan 29, 2016

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}};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants