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

WIP: Support nested keys #140

Closed
wants to merge 4 commits into from
Closed

Conversation

poteto
Copy link
Collaborator

@poteto poteto commented Dec 9, 2016

No description provided.

@dpigera
Copy link

dpigera commented Dec 14, 2016

@poteto Do you have an ETA on when this will get merged ?

@poteto
Copy link
Collaborator Author

poteto commented Jan 12, 2017

Sorry for the delay! Will get this over the line shortly.

@majnikov
Copy link

majnikov commented Feb 1, 2017

Hi @poteto , what about this PR?

@JCBarry
Copy link

JCBarry commented Feb 2, 2017

Hi there! Just ran into needing this as well. Is there a relevant workaround available?

@jbailey4
Copy link

jbailey4 commented Mar 1, 2017

@poteto Ran into this use case today, any idea when this could be merged? Glad to help with any work that may be needed.

@poteto
Copy link
Collaborator Author

poteto commented Mar 1, 2017

Sorry, work keeps getting in the way :( If someone would like to help me get this over the line I would be very grateful! This is how I'm thinking this feature will be implemented:

  1. Check if a key being set is nested
  2. Check if the change object has the object(s) required to set that value
    • true: use makeNestedObject to create the object(s)
    • false: no-op
  3. Set the value as normal
  4. Tests

@jbailey4
Copy link

jbailey4 commented Mar 1, 2017

@poteto I'll take a look at this tonight and see where I get. The work should be based on what you already have here in the feature/support-nested-keys branch, correct?

@poteto
Copy link
Collaborator Author

poteto commented Mar 1, 2017

Yup!

@jbailey4
Copy link

jbailey4 commented Mar 1, 2017

@poteto

Update:

It seems changeset relies on the setUnknownProperty to kick off the validation and then ultimately apply the change/error, but this isn't happening when attempting to set a nested prop. Instead, Ember is calling unknownProperty with the nested object name (first item in the path), which then calls _valueFor. This returns the underlying nested object, which Ember then basically continues on setting the intended value, without changeset ever knowing.

As a baseline first test I have the following:

set(dummyModel, 'contact', { phoneNumber: 1112223333 });

let expectedResult = [ { key: 'contact', value: { phoneNumber: 9998887777 } } ];
let dummyChangeset = new Changeset(dummyModel);

dummyChangeset.set('contact.phoneNumber', 9998887777);

assert.deepEqual(get(dummyChangeset, 'changes'), expectedResult, 'precondition'));

@poteto poteto force-pushed the feature/support-nested-keys branch from be45426 to 9c05fda Compare March 7, 2017 07:28
@poteto
Copy link
Collaborator Author

poteto commented Mar 7, 2017

I had another go at it with some inspiration from @jgwhite.

However there are still some weird issues I'm trying to figure out

  • Validate nested key
  • Be able to set more than 1 root nested key
  • Finish documentation

If anyone has any clues, please let me know...

@poteto poteto force-pushed the feature/support-nested-keys branch from 9c05fda to 052968c Compare March 7, 2017 07:32
@poteto poteto force-pushed the feature/support-nested-keys branch from 052968c to 2492bbf Compare March 7, 2017 07:36
@willrax
Copy link
Contributor

willrax commented Apr 4, 2017

hey @poteto, I'm trying to work on the points you wrote above. We would love to have nested validations in our application for a few "interesting" forms.

Are you committed to having this structure for the validations?

{
 name: validateWhatever(),
 "address.street_name": validateWhatever()
}

It seems at the moment you can't access keys that contain dots within ember objects, so accessing the validator function is tricky.

I'm @willrax on Slack if you want to discuss in more detail, but would you consider:

{
  name: validateWhatever(),
  address: {
    street_name: validateWhatever()
  }
}

as an alternative?

@poteto
Copy link
Collaborator Author

poteto commented Apr 5, 2017

I think the string option is the general practice in other ember validation libraries. I'm unsure what kind of extra complexity the object form would introduce, although in theory I think it should be the same code to retrieve the function via Ember.get

@willrax
Copy link
Contributor

willrax commented Apr 5, 2017

Ah right, If other libraries do it, it's probably best to stick to the convention then. I'll attempt to get the validations lookups (with the string keys) and that debugger in the tests at least hitting today.

@willrax
Copy link
Contributor

willrax commented Apr 5, 2017

Would you mind if we rebased (or merged) master in to this branch?

@willrax
Copy link
Contributor

willrax commented Apr 5, 2017

Had a quick look at some other libraries and it looks like internally they expand the string keys in to an object:

https://github.com/offirgolan/ember-cp-validations/blob/f0f8a92fdc2d09721b7acc4afd61fdbfae33e030/addon/validations/factory.js#L192

This gives people the string keys but then allows you to access the keys through the get set etc.

This seemed to not matter in the end. Doing validationsMap["org.ny.ny"] works fine.

@poteto
Copy link
Collaborator Author

poteto commented Apr 5, 2017

@willrax I don't mind! If you'd like, please open a PR merging into this branch feature/support-nested-keys

Also, huge thanks for stepping up to take this over the line!

* Add option to skip validations when setting values (#148)

* Add option to skip validations on setting values

* Rename option for skipping validation

* Change object merge to use pureAssign

* Update readme to reflect `skipValidate` option

* Update helper to pass along `skipValidate` option

* obj.hasOwnProperty(key) => key in obj (#151)

obj.hasOwnProerty(key) seems to be returning false for ember data models. key in obj  seems to work for me.

* [BUG]: clear errors for ember 1.13.13 (#157)

* [BUG]: clear errors for ember 1.13.13

* Update index.js

* Released v1.2.3

* Added isValidating and events (#152)

* Added isValidating function to changeset

* Added beforeValidation and afterValidation events

* Updated README.md for isValidating and events

* Update README.md

* Update index.js

* Update ember and friends (#165)

* update to ember-cli 2.8.0

* update to ember-cli 2.9.0

* update to ember-cli 2.10.1

* update to ember-cli 2.12.1

* remove bower from circle build

* update ember-try configuration

* remove bower install from circle setup

ember-cli removed the bower.json file so running this step causes the
tests to fail as it can't find the file.

* add ember 1.13 back to try tests

* add yarn lock file for yarn support (#164)

* allow empty objects (#166)
@minhnq013
Copy link

Hello, Just wondering if there is any news regarding this.

I am currently encountering this issue and there are workaround but it would be awesome if we can do nested property validation.

@willrax
Copy link
Contributor

willrax commented May 3, 2017

hey @minhnq013 Yep, still working on this 👍

@klclee
Copy link

klclee commented May 17, 2017

HI @willrax @poteto looks like this is really close to done? Anything I can do to move this along? Could really do with it then having individual changeset for each nested model 👍

@RobbieTheWagner
Copy link
Member

Would also love to get this merged. I've got arrays in my changeset that don't rollback, which is annoying. Let me know if there is any way I can help!

@webark
Copy link
Contributor

webark commented Aug 10, 2017

@nrcjbarry does my fork in #194 help? If not, what's the data structure?

@RobbieTheWagner
Copy link
Member

Bump, need to get the amazing work by @webark reviewed and merged! Would be great to add him as a collaborator, and I am happy to review and help out any way I can!

* Added ability to generate track changesets of nested values. Based off of the work done on #140

* added rollback support for nested values when set on the child changeset

* added test for an array that has been changed, rolledback, and saved to a nested object

* moving the deepset to a dependency rather then a dev dependency for propper instalation.

* added a missing comma. Will squash this when merging

* testing arrays of child changesets as well

* upgrading ember-cli and packages to latest to see if issue with clircle ci is resolved

* using yarn to globaly add bower. autocomplete failed me

* adding strict so that the travis tests will run.

* just some updates to the travis config to try to determin if it's a circle ci or travis issue

* Not understanding why travis is throwing a  error for somereson, so trying to get to the base of whats going on
@webark
Copy link
Contributor

webark commented Sep 14, 2017

Still getting that

Cannot find module 'is-absolute'
Error: Cannot find module 'is-absolute'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/ubuntu/ember-changeset/node_modules/npm/node_modules/which/which.js:12:18)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)

error every other circle ci test. I'm unsure what in circle ci is causing this error.

@steverhoades
Copy link

Curious if this feature has made any additional headway and if not what are the remaining items to be completed? Perhaps I can assist as I'd really like to see this introduced into Changeset.

@webark
Copy link
Contributor

webark commented Oct 5, 2017

@steverhoades as far as I'm concerned, everything is working as expected. We've gone back and forth on some extra tests, and all of those have been added and resolved. I am unsure as to why the circle ci build errors are occurring, but I didn't run into any errors locally, or with Travis. THere are some merge conflicts, but those are easier for a maintainer to resolve due to the back and forth with doing PR's on to side branches, but if that is a blocker I am more the willing to issue a pr against the side branch to resolve those issues.

@RobbieTheWagner
Copy link
Member

@webark I vote we just remove circle and rely on travis, since that is the supported CI for Ember addons out of the box anyway.

@steverhoades
Copy link

@webark @rwwagner90 I'm getting the following error when attempting to use this branch:

Error: Property set failed: object in path "mykeyname" could not be found or was destroyed.
    at new EmberError (error.js:38)
    at setPath (ember-metal.js:2764)
    at set (ember-metal.js:2692)
    at Class.addError (index.js:341)
    at Class._setProperty (index.js:538)
    at Class._validateAndSet (index.js:467)
    at index.js:292
    at Array.map (<anonymous>)
    at Class.validate (index.js:291)
    at Class.submit (component.js:58)

I am running Ember 2.15 as well as ember-changset-validations v1.2.8. I've also noticed that this branch is quite a bit behind master - does anyone have a rebased version of this branch somewhere? My first attempt at rebasing didn't result in working code.

@steverhoades
Copy link

@webark @rwwagner90 Please disregard my last message. I apologize, when i updated ember-changeset-validations it removed my link to ember-changeset. I do not see this error with this branch.

@steverhoades
Copy link

@webark @rwwagner90 @poteto I have verified that this works beautifully in our app. Would really like to see this released - how can I help?

@poteto
Copy link
Collaborator Author

poteto commented Oct 6, 2017

I would like to remove CircleCI as well, but in a separate PR. Does anyone have the bandwidth to help with rebasing this and resolving merge conflicts?

@steverhoades
Copy link

@poteto I'm attempting this now. If I can get something working i'll submit a PR.

steverhoades pushed a commit to steverhoades/ember-changeset that referenced this pull request Oct 6, 2017
* Added ability to generate track changesets of nested values. Based off of the work done on adopted-ember-addons#140

* added rollback support for nested values when set on the child changeset

* added test for an array that has been changed, rolledback, and saved to a nested object

* moving the deepset to a dependency rather then a dev dependency for propper instalation.

* added a missing comma. Will squash this when merging

* testing arrays of child changesets as well

* upgrading ember-cli and packages to latest to see if issue with clircle ci is resolved

* using yarn to globaly add bower. autocomplete failed me

* adding strict so that the travis tests will run.

* just some updates to the travis config to try to determin if it's a circle ci or travis issue

* Not understanding why travis is throwing a  error for somereson, so trying to get to the base of whats going on
@steverhoades
Copy link

@poteto @webark @rwwagner90 I've pushed a rebased version of this branch, tests are passing but I had to force update my branch and it will not cleanly integrate into this branch. I'm gonna give it another shot to see if I can get a cleaner result.

See steverhoades@44aefc0

steverhoades pushed a commit to steverhoades/ember-changeset that referenced this pull request Oct 6, 2017
* Added ability to generate track changesets of nested values. Based off of the work done on adopted-ember-addons#140

* added rollback support for nested values when set on the child changeset

* added test for an array that has been changed, rolledback, and saved to a nested object

* moving the deepset to a dependency rather then a dev dependency for propper instalation.

* added a missing comma. Will squash this when merging

* testing arrays of child changesets as well

* upgrading ember-cli and packages to latest to see if issue with clircle ci is resolved

* using yarn to globaly add bower. autocomplete failed me

* adding strict so that the travis tests will run.

* just some updates to the travis config to try to determin if it's a circle ci or travis issue

* Not understanding why travis is throwing a  error for somereson, so trying to get to the base of whats going on
@steverhoades
Copy link

@poteto @webark @rwwagner90 Ok, looks like this attempt is much much cleaner on the rebase side of things.. will provide PR.

steverhoades@d13917d

@nucleartide
Copy link
Contributor

Hey folks, since this is the issue/PR with the most activity, I'll try to find some time to review this and get it merged. As a newly appointed maintainer, I'd also like to start doing monthly releases in order to close out all the issues/PRs.

Hope that's okay with everyone!

@RobbieTheWagner
Copy link
Member

@nucleartide sounds great! Glad to have you on board 😄

@nucleartide
Copy link
Contributor

So I notice that this PR has some changes that aren't necessarily related to nested keys support. I'd like to break this PR into smaller ones, so the actual change is easier to review. 🙂

It seems like yarn test is also failing on master – will take a look at that first.

@webark
Copy link
Contributor

webark commented Nov 16, 2017

@nucleartide I was having issues with circle CI tests not passing, so I tried updating yarn and ember/ember-cli to see if that would resolve the issue, which it didn't. Feel free to pull out all the non-code changes, and put that into a separate PR.

@webark
Copy link
Contributor

webark commented Nov 16, 2017

some of the other stuff is coming through due to a poor merge confict.

@webark
Copy link
Contributor

webark commented Nov 16, 2017

@nucleartide I just created #211

#211 is what this PR should be if it was able to be done in a cleaner way. (doing PR's against long-lived branches that are not up to date with master.. has complexities)

@poteto
Copy link
Collaborator Author

poteto commented Nov 19, 2017

Closed by #211

@poteto poteto closed this Nov 19, 2017
@nucleartide nucleartide deleted the feature/support-nested-keys branch December 18, 2017 12:27
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.