Reputation: 2859
I have following two models
Nurse
Room
A room has belongsTo relation with the nurse model as defined below:
"relations": {
"nurse": {
"model": "Nurse",
"type": "belongsTo",
"foreignKey": "nid"
}
}
which works fine and produces the data on following urls
but when I try the embedsOne relation as defined below:
"relations": {
"nurse": {
"model": "Nurse",
"type": "embedsOne",
"foreignKey": "nid"
}
}
and try accessing url at
I get the following error:
message: "ER_BAD_FIELD_ERROR: Unknown column '_nurse' in 'field list'",
thoughts?
Upvotes: 3
Views: 477
Reputation: 1648
embedsOne relation does not have foreignKey. You should use "property" as is shown in documentation: (https://docs.strongloop.com/display/public/LB/Embedded+models+and+relations#Embeddedmodelsandrelations-EmbedsOne)
"relations": {
"address": {
"type": "embedsOne",
"model": "Address",
"property": "billingAddress"
}
}
then your object will look like
{
id: 1,
name: 'John Smith',
billingAddress: {
street: '123 Main St',
city: 'San Jose',
state: 'CA',
zipCode: '95124'
}
}
Upvotes: 1