【发布时间】:2016-07-12 14:47:10
【问题描述】:
我在我的项目中使用环回,并且我有一个与 SellerRequests 模型相关的 MyUser 模型(hasMany)。
我看到我现在可以在 /api/MyUsers/:id/sellerRequests 上进行 POST 以创建链接到用户的新 SellerRequest 但我想做的是在我的 common/my-user 中使用此远程方法.js 文件。
我尝试执行 MyUser.__create__sellerRequests 但这未定义(MyUser.prototype.__create__sellerRequests 和 MyUser.createSellerRequests 也是如此)。 知道如何访问远程方法吗?
谢谢!
// here is my common/my-user.js file
module.exports = function(Myuser) {
console.log(Myuser.__create__sellerRequests); // This is undefined
}
// Here is my MyUser.json
{
"name": "MyUser",
"base": "User",
"strict": false,
"idInjection": false,
"options": {
"validateUpsert": true
},
"properties": {
"firstname": {
"type": "string"
},
"lastname": {
"type": "string"
},
"gender": {
"type": "number"
},
"birthday": {
"type": "string"
},
"country": {
"type": "string"
},
"description": {
"type": "string"
},
"spokenLanguages": {
"type": "string"
},
"phoneNumber": {
"type": "string"
},
"createdAt": {
"type": "date",
"defaultfn": "now"
}
},
"validations": [],
"relations": {
"sellers": {
"type": "hasMany",
"model": "Seller",
"foreignKey": "customer_id"
},
"sellerRequests": {
"type": "hasMany",
"model": "SellerRequest",
"foreignKey": "customer_id"
}
},
"acls": [
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "patchAttributes"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "avatar"
},
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "defaultAvatar"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "avatarUpload"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "avatarDelete"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__create__sellerRequests"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__destroyById__sellerRequests"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__get__sellerRequests"
},
{
"principalType": "ROLE",
"principalId": "$owner",
"permission": "ALLOW",
"property": "__findById__sellerRequests"
}
],
"methods": {}
}
【问题讨论】:
-
你的 MyUser.json 是什么?
标签: javascript node.js loopbackjs strongloop