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

Fixes #1417 #1420

Merged
Merged

Conversation

drew-gross
Copy link
Contributor

Pretty ugly solution but it does the trick.

@@ -647,31 +646,84 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals

Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we do something like

if (isNestedObject) {
   let transformableKeys = ["_id", ...];
   Object.keys(mongoObject).forEach((key) => {
     if (transformableKeys.indexOf(key) > -1) {
       restObject[key] = untransformObject(schema, className, mongoObject[key], true);
     } else {
       restObject[key] = mongoObject[key];
     }
  });
  return restObject;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I will refactor

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe move let transformableKeys some where else, and if we get crazy we could have a structure like:

transformKey: {
   key: {
       nested: (key, mongoObject, restObject) => {
           // to the mongoObjectTransform and assign on restObject
       },
       default: (key, mongoObject, restObject) => {
           // to the mongoObjectTransform and assign on restObject
       },
   }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with something simpler. Moving this logic all to the mongo adapter will be a better time to fix it up.

@facebook-github-bot
Copy link

@drew-gross updated the pull request.

'expiresAt',
'_expiresAt',
];
if (_.includes(specialKeys, key) && isNestedObject) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should switch these two statements around so the if will exit early with the boolean compare rather than a Object key iteration

if(isNestedObject && _.includes(specialKeys, key)) {
    // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Thanks.

@facebook-github-bot
Copy link

@drew-gross updated the pull request.

@drew-gross
Copy link
Contributor Author

Hmmm travis isn't picking up this commit....

@blacha
Copy link
Contributor

blacha commented Apr 8, 2016

It also missed building #1416

@drew-gross
Copy link
Contributor Author

Whoops. Guess we better not do a release until we get passing tests.

@flovilmart flovilmart closed this Apr 8, 2016
@flovilmart flovilmart reopened this Apr 8, 2016
@flovilmart
Copy link
Contributor

meh...

@codecov-io
Copy link

Current coverage is 92.77%

Merging #1420 into master will decrease coverage by -0.02% as of 4949738

@@            master   #1420   diff @@
======================================
  Files           87      87       
  Stmts         5479    5483     +4
  Branches      1011    1012     +1
  Methods          0       0       
======================================
+ Hit           5084    5087     +3
  Partial         10      10       
- Missed         385     386     +1

Review entire Coverage Diff as of 4949738

Powered by Codecov. Updated on successful CI builds.

@@ -647,6 +645,25 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals

var restObject = untransformACL(mongoObject);
for (var key in mongoObject) {
const specialKeys = [
Copy link
Contributor

Choose a reason for hiding this comment

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

should we move that up? I don't think that behaves as a static in Obj-C

Copy link
Contributor

Choose a reason for hiding this comment

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

If babel is anything like typescript that would just be converted to var specialKeys

So ideally this should be declared outside of the function, or at the very least outside of the loop.

@facebook-github-bot
Copy link

@drew-gross updated the pull request.

_tombstone: {
_updated_at: "I'm sure people will nest keys like this",
_acl: 7,
_id: {}
Copy link
Contributor

Choose a reason for hiding this comment

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

can you throw in a regular key there? (see the other comment)

@drew-gross drew-gross force-pushed the fix-nested-special-keys branch from ebb4ad9 to 3959929 Compare April 8, 2016 22:30
@drew-gross
Copy link
Contributor Author

Passed locally even with regular keys

@facebook-github-bot
Copy link

@drew-gross updated the pull request.

@flovilmart
Copy link
Contributor

Merging then!

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

Successfully merging this pull request may close these issues.

5 participants