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

Javascript error when trying to merge model with null value for relation #215

Closed
davincho opened this issue Sep 20, 2015 · 2 comments
Closed
Assignees
Labels

Comments

@davincho
Copy link
Contributor

Code that reproduces the error: http://plnkr.co/edit/aJb2dKSVG7JE4CNucmYy?p=preview

We have two simple models:

var Prod = store.defineResource({
    name: 'prod',
    relations: {
      hasOne: {
        comment: {
          localField: 'comment',
          foreignKey: 'prod_id'
        }
      }
    }
  });

  var Comment = store.defineResource({
    name: 'comment'
  });

Let's inject new prod object with nested comment object:

Prod.inject({
    id: 1,
    comment: {
      id: 3,
      prod_id: 1
    }
  });

Now inject a new prod object with the same id (=merge as specified in http://www.js-data.io/docs/dsdefaults#onconflict) and a null value for comment:

Prod.inject({
     id: 1,
     name: 'test',
     comment: null
  });

Result: Javascript error in https://github.com/js-data/js-data/blob/master/dist/js-data.js#L2912 as obj is null.

shot

I would suggest to skip null values when being merged.

@jmdobry jmdobry added the bug label Sep 20, 2015
@jmdobry jmdobry self-assigned this Sep 20, 2015
@davincho
Copy link
Contributor Author

@jmdobry thx a lot, you are awesome!

@jmdobry
Copy link
Member

jmdobry commented Sep 21, 2015

The fix will be available when 2.4.0 is released.

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

No branches or pull requests

2 participants