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