Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

property name with type is not working correctly with loopback complex model #4131

Closed
PRAKASH-SIVAGURUNATHAN opened this issue Feb 7, 2019 · 7 comments

Comments

@PRAKASH-SIVAGURUNATHAN
Copy link

PRAKASH-SIVAGURUNATHAN commented Feb 7, 2019

We have a model definition as follows

{
  "name": "accounts",
  "plural": "accounts",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string"
    },
    "items": {
      "type" : {
          "itemname": { "type": "string"},
          "type": { "type": "string" }
      }
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

In explorer the structure of the items is coming as shown below

screen shot 2019-02-07 at 12 23 09 pm

When we test the model by providing the values for items property, the response does not have a valid structure for items
screen shot 2019-02-07 at 12 29 30 pm

@PRAKASH-SIVAGURUNATHAN
Copy link
Author

NOTE: If we have the property name as type in the top-level it works fine. Loopback is behaving differently only when the type model property is defined within a complex structure.

@bajtos bajtos added the customer label Feb 7, 2019
@jannyHou
Copy link
Contributor

jannyHou commented Feb 7, 2019

Hi @PRAKASH-SIVAGURUNATHAN could you fork https://github.com/strongloop/loopback-sandbox and provide some example code to reproduce your error? Thanks. I can help you investigate.

From your description, a property named "type" has conflict with some code in https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/model-builder.js, it will be quicker for us to debug with a sample app.

@PRAKASH-SIVAGURUNATHAN
Copy link
Author

@jannyHou : I have created an forked branch of loopback-sandbox and pushed the model which our product is using. Please refer to the forked branch of
https://github.com/PRAKASH-SIVAGURUNATHAN/loopback-sandbox

@hacksparrow hacksparrow self-assigned this Feb 13, 2019
@hacksparrow
Copy link
Member

Thanks for the sample app @PRAKASH-SIVAGURUNATHAN. I can confirm it as a bug. Taking a look at the cause and trying to find a fix.

@hacksparrow
Copy link
Member

@PRAKASH-SIVAGURUNATHAN which connector are you using, by the way?

@hacksparrow
Copy link
Member

Bug is caused by the sub-property name type conflicting with internal Model properties. Relevant files - https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/model-definition.js#L237, https://github.com/strongloop/loopback-datasource-juggler/blob/master/lib/model-builder.js#L886.

We are already not allowing constructor as a top level key. type works fine as a top level key, but causes conflict when used as a sub-key.

I am working on a solution.

@hacksparrow
Copy link
Member

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

5 participants