javascriptnode.jsloopbackjs

Hide nested properties in loopback model


I am creating a loopback model (model1) which refers to another model and want to hide some properties of the nested model (model2). Also, I just want them to be hidden in this model1. How can I solve this issue ?

I have tried the property hidden, which works fine with the current model1 properties but not with the nested model2 properties.

{
  "name": "Model1",
  "base": "PersistedModel",
  "idInjection": true,
 ...
  "properties": {
    "pet": {
      "type": "Model2",
    }
 ...
}

{
  "name": "Model2",
 ...
  "properties": {
    "name": {
      "type": "string",
    }
 ...
}

I want here to hide the property "name" from Model2 in the Model1 explorer

Thanks !


Solution

  • Did you check include-with-filter documentation. I hope this should solve your problem or else share some more descriptive code that you have tried so far.

    Here's another example that uses the predefined model relations to include selective fields from the related models.

    {"include": [  
      {"relation":"relationName", 
       "scope":{"fields": ["Field1","Field2"]} 
      },
      {"relation":"relation2Name", 
       "scope":{"fields": ["Field3","Field4"]} 
      },
    ]}
    

    Note: you won't be able to hide Ids