2016-07-12 3 views
0

私は自分のプロジェクトでループバックを使用しており、MyUserモデルはSellerRequestsモデルに関連しています(hasMany)。ユーザーにリンクされている新しいsellerRequestを作成するには、ID/sellerRequestsしかし、私がやりたいことは、私の共通でこのリモートメソッドを使用することです:私は/私は今/ API/MyUsersにPOSTを作ることができることがわかりループバックはリレーションのリモートメソッドを使用します


/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": {} 
} 
+0

MyUser.jsonとは何ですか? –

答えて

0

ユーザーインスタンスを取得し、データがSellerRequestモデルのフィールドと値を含むオブジェクトである。この

<user instance>.sellerRequests.create(data, function(error, result) { 

}); 

を使用します。

またはこの

MyUser.sellerRequests({customer_id: <user_id>, <rest of the fields in seller requests>}, function(error, result) { 

}); 

リファレンスを使用しますMethods available to the modelを。

+0

魅力のように動作します、ありがとう! – achauchet