Skip to content

dao: should not convert the val type if object#711

Closed
yorkie wants to merge 1 commit into
loopbackio:masterfrom
yorkie:patch-1
Closed

dao: should not convert the val type if object#711
yorkie wants to merge 1 commit into
loopbackio:masterfrom
yorkie:patch-1

Conversation

@yorkie

@yorkie yorkie commented Sep 2, 2015

Copy link
Copy Markdown

If the value is an object, maybe we should not convert it to corresponding type like supporting:

{ '$exists': true }

/cc @raymondfeng

@slnode

slnode commented Sep 2, 2015

Copy link
Copy Markdown

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@raymondfeng

Copy link
Copy Markdown
Contributor

@yorkie Thank you for the patch. Can you provide a test case to demonstrate what issue you are trying to solve? We'll include the test when the PR is merged.

@yorkie

yorkie commented Sep 3, 2015

Copy link
Copy Markdown
Author

Hey @raymondfeng I'm fixing the same issue at strongloop/loopback#646, because I was occurring as well, and this patch should just provide a ability to use MongoDB's any $ operator without supporting by loopback.

If you think this is valuable, I will add the test case :)

@yorkie

yorkie commented May 3, 2016

Copy link
Copy Markdown
Author

Ping @raymondfeng :-)

@slnode

slnode commented May 3, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@superkhau

Copy link
Copy Markdown
Contributor

@yorkie Thank you for the patch. Can you provide a test case to demonstrate what issue you are trying to solve? We'll include the test when the PR is merged.

Can you add a test case please?

Comment thread lib/dao.js Outdated
} else if (operator === 'regexp' && val instanceof RegExp) {
// Do not coerce regex literals/objects
} else if (!((operator === 'like' || operator === 'nlike') && val instanceof RegExp)) {
} else if (!((operator === 'like' || operator === 'nlike') && val instanceof Object)) {

@superkhau superkhau May 3, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add another || for your case. Why is the RegExp check being changed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I have said in description, current loopback's where filter doesn't support complicated query which contains something mongoDB operators in an object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part I understand. But why not .. && (val instanceof RegExp || val instanceof Object)) {?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I guess the RegExp is also an Object?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is, but you hide the fact that you're checking for RegExp explicitly when you combine them together.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that makes sense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to make that change and then we can get it merged in?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also write a unit test to verify your changes and prevent regressions in the future?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will update nits and add test case ASAP :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY, ping me again after and I will get it merged in ASAP. ;)

@superkhau superkhau assigned superkhau and unassigned raymondfeng May 6, 2016
@yorkie

yorkie commented May 7, 2016

Copy link
Copy Markdown
Author

@superkhau I have added the test case and fix nits, could you please have a review again? Thank you :-)

@superkhau

Copy link
Copy Markdown
Contributor

Can you run the tests through the linter? I see some stylistic issues that will probably cause linting to fail.

npm test

@superkhau

Copy link
Copy Markdown
Contributor

Can you also squash the commits?

@yorkie

yorkie commented May 9, 2016

Copy link
Copy Markdown
Author

Hey @superkhau the npm test seems not include the lint check?

@yorkie

yorkie commented May 9, 2016

Copy link
Copy Markdown
Author

Done the squash :-)

@superkhau

superkhau commented May 9, 2016

Copy link
Copy Markdown
Contributor

I just looked, it does, but still uses makefiles (which we are in the process of removing). However the lint code is there, so you should be able to run npm run lint manually. ;) Please try that instead.

@bajtos

bajtos commented May 10, 2016

Copy link
Copy Markdown
Member

ability to use MongoDB's any $ operator without supporting by loopback.

FWIW, we already support MongoDB's $ operators in DAO.updateAttributes, one has to enable that feature via model-level setting allowExtendedOperators. Perhaps we should do the same here and enable this feature only when the flag is enabled?

@yorkie

yorkie commented May 10, 2016

Copy link
Copy Markdown
Author

@bajtos do you mean check allowExtendedOperators here?

@bajtos

bajtos commented May 10, 2016

Copy link
Copy Markdown
Member

do you mean check allowExtendedOperators here?

Yes, that's correct, allow MongoDB-like object values in query only when allowExtendedOperators is turned on. Sorry for not being more clear!

However, I am not sure if it's the right thing to do. I'd rather leave it up to you, @raymondfeng and @superkhau to decide.

@yorkie

yorkie commented May 10, 2016

Copy link
Copy Markdown
Author

Okay, I will fix the lint warnings pointed by @superkhau firstly :-)

@yorkie

yorkie commented May 10, 2016

Copy link
Copy Markdown
Author

Fixed and did rebase @superkhau :-)

@superkhau

Copy link
Copy Markdown
Contributor

@raymondfeng Input on the above comments?

@superkhau

Copy link
Copy Markdown
Contributor

Note, I spoke to @raymondfeng regarding the flag, we want it implemented to work with allowExtendedOperators.

@yorkie

yorkie commented May 17, 2016

Copy link
Copy Markdown
Author

Ok, got it, I will do it soon later :-)

@yorkie

yorkie commented May 18, 2016

Copy link
Copy Markdown
Author

Hey @superkhau @raymondfeng Do you have something documentation about the config allowExtendedOperators?

@superkhau

Copy link
Copy Markdown
Contributor

@crandmck ^

@crandmck

crandmck commented May 18, 2016

Copy link
Copy Markdown
Contributor

Do you have something documentation about the config allowExtendedOperators?

What we have is just for Mongo: https://docs.strongloop.com/display/APIC/MongoDB+connector#MongoDBconnector-UsingMongoDBoperatorsinupdateoperations

IIUC, this change means you can use it with other data sources--right? If so, which ones?
And is the config the same in <modelname>.json ?

@superkhau

superkhau commented May 18, 2016

Copy link
Copy Markdown
Contributor

IIUC, this change means you can use it with other data sources--right? If so, which ones?

Not sure about this one (I believe it is for all connectors since we are modifying DAO), but @bajtos or @raymondfeng can confirm this.

And is the config the same in .json ?

Yes, the config is the same.

@crandmck

Copy link
Copy Markdown
Contributor

If it's only Mongo, then what does this add over what's already documented?

u.order.should.equal(1);
u.name.should.equal('Paul McCartney');
User.findOne({ order: 'order' }, function(err, user) {
should.not.exist(err);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should change this to if (err) return done(err) for better error output.

@superkhau

Copy link
Copy Markdown
Contributor

@yorkie is adding a feature that will only turn on if allowExtendedOperators is set to true in the config, so it doesn't really depend on the connector.

If it's only Mongo, then what does this add over what's already documented?

It's a change to DAO so it will affect all connectors.

@superkhau

Copy link
Copy Markdown
Contributor

@bajtos Reassigning this one to you as I'll be gone for a few weeks. It's pretty close to done.

@superkhau superkhau assigned bajtos and unassigned superkhau May 20, 2016
User.findOne(function(err, user) {
should.not.exist(err);
should.exist(user);
user.id.toString().should.equal(users[0].id.toString());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, this change is cleaning up the code by renaming e, u to err, user. While I see a lot of value in clean code, I see much more value in git commit history that makes code archaeology easy. Changes like these makes examination of history more difficult, as they add noise.

If you think this is still a change worth making, then please put it in a standalone commit, possibly in a new pull request.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked @yorkie to change it to err/user earlier because I didn't realize it was already named e/u. My bad! @yorkie Can you change it back to so these irrelevant lines aren't part of this commit?

@bajtos

bajtos commented Dec 5, 2016

Copy link
Copy Markdown
Member

Closing in favour of #1180

@slnode

slnode commented Dec 5, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

2 similar comments
@slnode

slnode commented Dec 5, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

@slnode

slnode commented Dec 5, 2016

Copy link
Copy Markdown

Can one of the admins verify this patch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants