LoopbackJS / AngularJS查找关系hasOne包含分隔属性

时间:2015-12-03 23:39:01

标签: mysql loopbackjs relation strongloop has-one

我在mysql db中使用loopbackapi在angularjs中进行查找查询。

我有一个与另一个具有hasOne关系的模型。

Empresa hasOne Operadora

当我使用include args在Empresa中进行查找时,它会给我带来Operadora属性,但它包含Empresa中的属性,但我希望将它分开。

我使用这些例子进行了测试:

Empresa.findOne({ include: {"relation" : 'Operadora', 'as': 'Operadora'}
Empresa.findOne({ include: {model: 'Operadora', 'as': 'Operadora'} 
Empresa.findOne({ include: {Operadora: 'Operadora'}
Empresa.findOne({ include:  'Operadora'
Empresa.find({ include: {"relation": 'Operadora'}

它让我这样:

Empresa.nome
Empresa.nomeOperador

但我想:

Empresa.nome
Empresa.Operadora.nomeOperador

empresa.json

{
  "name": "Empresa",
  "base": "PersistedModel",
  "idInjection": false,
  "options": {
    "validateUpsert": true
  },
  "mysql": {
    "schema": "netexamesapp_prod",
    "table": "Empresa"
  },
  "properties": {
    "id": {
      "type": "Number",
      "id": true,
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "id",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "N"
      },
      "_selectable": false
    },
    "usuario": {
      "type": "Number",
      "required": true,
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "usuario",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "N"
      },
      "_selectable": false
    },
    "numcartprof": {
      "type": "String",
      "required": false,
      "length": 255,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "numCartProf",
        "dataType": "varchar",
        "dataLength": 255,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "numregcons": {
      "type": "String",
      "required": false,
      "length": 255,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "numRegCons",
        "dataType": "varchar",
        "dataLength": 255,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "tipocontratacao": {
      "type": "String",
      "required": false,
      "length": 255,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "tipoContratacao",
        "dataType": "varchar",
        "dataLength": 255,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "numcnes": {
      "type": "String",
      "required": false,
      "length": 255,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "numCNES",
        "dataType": "varchar",
        "dataLength": 255,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "dataexpcro": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "dataExpCRO",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "operadora": {
      "type": "Number",
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "operadora",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "N"
      },
      "_selectable": false
    },
    "datacredenciamento": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "dataCredenciamento",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "datadescredenciamento": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "dataDescredenciamento",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "created": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "created",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "lastupdated": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "lastUpdated",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "nomefantasia": {
      "type": "String",
      "required": false,
      "length": 255,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "nomefantasia",
        "dataType": "varchar",
        "dataLength": 255,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "cnpj": {
      "type": "String",
      "required": false,
      "length": 255,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "cnpj",
        "dataType": "varchar",
        "dataLength": 255,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "razaosocial": {
      "type": "String",
      "required": false,
      "length": 255,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "razaosocial",
        "dataType": "varchar",
        "dataLength": 255,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    }
  },
  "validations": [],
  "relations": {
        "User": {
         "type": "belongsTo",
         "model": "User",
         "foreignKey": "usuario"
       },
       "Local": {
         "type": "belongsTo",
         "model": "Local",
         "foreignKey": "endereco"
       },
       "Operadora": {
         "type": "hasOne",
         "model": "Operadora",
         "foreignKey": "empresa"
       }
  },
  "acls": [],
  "methods": {}
}

operadora.json

{
  "name": "Operadora",
  "base": "PersistedModel",
  "idInjection": false,
  "options": {
    "validateUpsert": true
  },
  "mysql": {
    "schema": "netexamesapp_prod",
    "table": "Operadora"
  },
  "properties": {
    "id": {
      "type": "Number",
      "id": true,
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "id",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "N"
      },
      "_selectable": false
    },
    "usuario": {
      "type": "Number",
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "usuario",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "N"
      },
      "_selectable": false
    },
    "datacredenciamento": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "dataCredenciamento",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "datadescredenciamento": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "dataDescredenciamento",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "created": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "created",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "lastupdated": {
      "type": "Date",
      "required": false,
      "length": null,
      "precision": null,
      "scale": null,
      "mysql": {
        "columnName": "lastUpdated",
        "dataType": "datetime",
        "dataLength": null,
        "dataPrecision": null,
        "dataScale": null,
        "nullable": "Y"
      },
      "_selectable": true
    },
    "empresa": {
      "type": "Number",
      "required": false,
      "length": null,
      "precision": 10,
      "scale": 0,
      "mysql": {
        "columnName": "empresa",
        "dataType": "int",
        "dataLength": null,
        "dataPrecision": 10,
        "dataScale": 0,
        "nullable": "Y"
      },
      "_selectable": true
    }
  },
  "validations": [],
  "relations": {
       "User": {
         "type": "belongsTo",
         "model": "User",
         "foreignKey": "usuario"
       },
       "Empresa": {
         "type": "belongsTo",
         "model": "Empresa",
         "foreignKey": "empresa"
       }
     },
  "acls": [],
  "methods": {}
}

任何想法怎么做?

0 个答案:

没有答案