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

Allow for unnamed attributes #125

Merged

Conversation

cbarrese
Copy link
Contributor

This is an attempt to address issue #107

I pulled the code out of the conversation, modified slightly to get it to work, and wrote a couple of tests against it. I'm looking for some validation that this is on the right track and what else you'd like to see in terms of test coverage and documentation in order to accept this pull request.

for(var name in model) {
if(!model.hasOwnProperty(name)){
continue;
}
Copy link
Contributor Author

@cbarrese cbarrese Apr 11, 2017

Choose a reason for hiding this comment

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

Needed to add this continue in order to avoid trying to turn schema, options, ..., etcetera into Attribute objects that would attempt to be persisted.

dynamoObj[attr.name] = dynamoAttr;

if(!attr & this.options.saveUnknown) {
attr = Attribute.create(this, name, typeof model[name]);
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 think the typeof here works better than always assuming Object. JSON.stringify doesn't always give you what you'd want.

> JSON.stringify("astring")
'"astring"'

for(var name in model) {
if(!model.hasOwnProperty(name)){
continue;
}
Copy link

Choose a reason for hiding this comment

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

think you can just use Object.getOwnPropertyNames(),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tried that and had a bunch of test failures that didn't seem worth tracking down since the solution above worked.

@@ -254,7 +254,7 @@ describe('Query', function (){
Dog.query('breed').eq('unknown')
.filter('color').not().null().exec()
.then(function (dogs) {
dogs.length.should.eql(5);
dogs.length.should.eql(4);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

based on the test data setup, this assertion was wrong

@@ -268,7 +268,7 @@ describe('Query', function (){
.filter('color').not().eq('Brown')
.exec()
.then(function (dogs) {
dogs.length.should.eql(1);
dogs.length.should.eql(2);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

based on the test data setup, this assertion was wrong

@brandongoode
Copy link
Contributor

Thanks for the PR. I know several people will be happy to get this.

The code and test cases look good (I wonder how the Query tests have been passing - thanks for fixing that).

Could you add a few quick line to the schema options section of the README? -
https://github.com/automategreen/dynamoose#options

@brandongoode brandongoode added this to the v0.8.0 milestone Apr 14, 2017
@brandongoode brandongoode merged commit 8720e09 into dynamoose:master Apr 14, 2017
@brandongoode
Copy link
Contributor

Thanks a bunch.

@brandongoode brandongoode mentioned this pull request Jun 1, 2017
4 tasks
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.

None yet

3 participants