0

I have the following model definition in a loopback project: `

{
  "name": "Program",
  "base": "PersistedModel",

  "properties": {
    "sId": {
      "type": "string",
      "required": true,
      "length": 20
    },
    "Category": {
      "type": "string",
      "length": 255,
      "description": "Category"
    },
    "ProgramName": {
      "type": "string",
      "length": 255,
      "description": "Program Name"
    },
    "Program_Status": {
      "type": "string",
      "length": 255,
      "description": "Program Status"
    }
  },
  "validations": [],
  "relations": {
    "account": {
      "type": "belongsTo",
      "model": "Account",
      "foreignKey": "Account__c",
      "primaryKey": "sId"
    },
  },
  "methods": {}
}

`

I want to get value of description defined in field name in any other model. Is there anyway in loopback or express.js to get it?

  • what ? do you just want to access `description` property ? – Muhammad Usman Jul 10 '18 at 05:42
  • I haven't seen that usage, but for a workaround solution, you can use "require" to include the json file of the model directly. – tashakori Jul 10 '18 at 07:17
  • @GeorgeBailey Actually, I need to define field label in description property. I have used a similar approach in CakePHP model but couldn't find any way in loopback. – Nitish kumar Jul 10 '18 at 12:03

1 Answers1

0

It's only possible via javascript code. I'm afraid there isn't a way to access json files properties from another json file.

In yourOtherModel.js

module.exports = function(yourOtherModel){
var programProps = yourOtherModel.app.models.Program.properties;

//Your props
var programDescription = programProps.Category.description;
}
bmvr
  • 817
  • 2
  • 9
  • 25