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

null value not persisted for properties of type JSON, Any, or Object #1895

Closed
ewrayjohnson opened this issue Jul 12, 2021 · 2 comments · Fixed by #2080 · May be fixed by #1899
Closed

null value not persisted for properties of type JSON, Any, or Object #1895

ewrayjohnson opened this issue Jul 12, 2021 · 2 comments · Fixed by #2080 · May be fixed by #1899

Comments

@ewrayjohnson
Copy link

ewrayjohnson commented Jul 12, 2021

Steps to reproduce

  1. Create a model with a property of either of the following types: JSON, Any, or Object
  2. Ensure the property above is not required.
  3. Create an instance of the above model setting the property value to null
  4. Query the model where the value of the property is null and see that the created instance is not returned

Current Behavior

'null' is stored in the dataSource

Expected Behavior

null is stored in the dataSource

Proposed fix

Replace this:

    if (type === 'JSON' || type === 'Any' || type === 'Object' || data[propName] instanceof Array) {
      res[propName] = JSON.stringify(data[propName]);
    } else {
      res[propName] = data[propName];
    }

With this:

    const value = data[propName];
    if (value !== null && (type === 'JSON' || type === 'Any' || 
        type === 'Object' || value instanceof Array)) {
      res[propName] = JSON.stringify(value);
    } else {
      res[propName] = value;
    }

Additional information

win32 x64 12.18.3
"loopback": "^3.28.0",
"loopback-datasource-juggler": "^3.28.0",

Related Issues

Could not find a related issue

@stale
Copy link

stale bot commented Sep 10, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 10, 2021
@achrinza achrinza removed the stale label Sep 10, 2021
achrinza pushed a commit that referenced this issue Sep 12, 2021
@stale
Copy link

stale bot commented Nov 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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