回环查询与参加环回

问题描述:

,我开始用这个模型:回环查询与参加环回

[ 
    { 
    "mov_id": 0, 
    "mov_tipo": "string", 
    "mov_valore": 0, 
    "mov_causale_fk": 0, 
    "mov_conto_fk": 0, 
    "mov_data": "2017-10-04T09:02:19.620Z", 
    "mov_note": "string", 
    "mov_utente_fk": 0, 
    "mov_aggiunta": "2017-10-04T09:02:19.620Z" 
    } 
] 

然后我加了两个关系,这符合两国外交钥匙在我的MySQL数据库:

"relations": { 
    "causale_fk": { 
     "type": "hasOne", 
     "model": "causali", 
     "foreignKey": "causale_id", 
     "options": { 
     "nestRemoting": true 
     } 
    }, 
    "conto_fk": { 
     "type": "hasOne", 
     "model": "conti", 
     "foreignKey": "conto_id", 
     "options": { 
     "nestRemoting": true 
     } 
    } 
    }, 

我也要喜欢看这些模型中的字段,就像我用JOIN做了一个查询一样。 这是可能的?

好的,我解决了范围。

这是模型:

{ 
    "name": "movimenti", 
    "plural": "movimenti", 
    "base": "PersistedModel", 
    "idInjection": true, 
    "options": { 
    "validateUpsert": true 
    }, 
    "scope": { 
    "include": [ 
     "causale_fk", 
     "conto_fk" 
    ] 
    }, 
    "properties": { 
    "mov_id": { 
     "type": "number", 
     "id": true, 
     "required": true 
    }, 
    "mov_valore": { 
     "type": "number", 
     "required": true 
    } 
    }, 
    "validations": [], 
    "relations": { 
    "causale_fk": { 
     "type": "hasOne", 
     "model": "causali", 
     "foreignKey": "causale_id" 
    }, 
    "conto_fk": { 
     "type": "hasOne", 
     "model": "conti", 
     "foreignKey": "conto_id", 
     "include": "conti" 
    } 
    }, 
    "acls": [], 
    "methods": {} 
} 

再见!

您可以在过滤器中添加选项,并且您需要设置的特定选项是include。查询​​了解更多详情。

这是给你的特殊需要一个例子:

{ 
Model.find({include:['causale_fk','conto_fk']}, function(){}); 
}