0

I am trying to take data from a single form that has the user credentials along with user details and store them in seperate models in loopback. I have created the required models and relations but I am confused on how to do this. Does this happen automatically since the relations are specified or do i have to make use of the afterRemote method to do so ?

There are my models

    {
    "name": "userdetails",
    "base": "PersistedModel",
    "idInjection": true,
    "options": {
        "validateUpsert": true
    },
    "properties": {
        "first_name": {
            "type": "string",
            "required": true
        },
        "last_name": {
            "type": "string",
            "required": true
        },
        "primary_contact": {
            "type": "string",
            "required": true
        },
        "company_name": {
            "type": "string",
            "required": true
        }
    },
    "validations": [],
    "relations": {
        "User": {
            "type": "belongsTo",
            "model": "user",
            "foreignKey": "userId"
        }
    },
    "acls": [],
    "methods": []
}

and the second model

{
"name": "user",
"plural": "users",
"base": "User",
"idInjection": true,
"options": {
    "validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {
    "UserDetails": {
        "type": "hasOne",
        "model": "userdetails",
        "foreignKey": "userId"
    }
},
"acls": [{
    "accessType": "EXECUTE",
    "principalType": "ROLE",
    "principalId": "$unauthenticated",
    "permission": "DENY",
    "property": "GET"
}],
"methods": []

}

I have looked at the loopback angular admin project and am trying to use it as the reference point for this but so far I have been unsuccessful in figuring this out. Any pointers on this would be appreciated. Thanks

Bazinga777
  • 5,140
  • 13
  • 53
  • 92

1 Answers1

0

I think this is the answer you might be looking for. I asked about how to save on 3 different models through 1 endpoint.

Save multiple models in loopback

In essence, you create a new remoteMethod endpoint that will allow you to save all your parameters you pass it. You can't override much of the standard CRUD operations on the models

This new remoteMethod endpoint might also be more preferred so that you keep your standard Create/Update methods the way they are.

Community
  • 1
  • 1
Handonam
  • 618
  • 8
  • 17