I am using loopback in my project and I have a MyUser model related (hasMany) to a SellerRequests model.
I see that I can now make a POST on /api/MyUsers/:id/sellerRequests to create a new sellerRequest linked to the user but what I want to do is to use this remote method in my common/my-user.js file.
I try to do a MyUser.__create__sellerRequests but this is undefined (same thing for MyUser.prototype.__create__sellerRequests and MyUser.createSellerRequests). Any idea how to access the remote method ?
Thanks !
// 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": {}
}