-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
In the following code I believe self.$hasMany should be self.$hasOne
for(var rel in self.$hasOne) {
if(rel === name) {
self[rel] = self.$mapping[rel]();
var id = self[self.$hasMany[rel].id]; //mandatory
var field = self.$hasMany[rel].field || null;
return self[rel].$get(id,field);
}
}
Also, I am getting the following error when trying to use this code:
TypeError: Cannot read property 'apply' of undefined
line of code that throws the error is:
self[rel] = self.$mapping[rel]();
My User model:
return ModelCore.instance({
$type : "Users", //Define the Object type
$pkField : "id", //Define the Object primary key
$mapping : {
id : null,
Profiles : Profiles,
},
$hasOne : { // Define Relations
Profiles : {
id : "id",
field : "user_id" //field to be searched on Profile model
}
},
My Profile model:
return ModelCore.instance({
$type : "Profiles", //Define the Object type
$pkField : "id", //Define the Object primary key
$mapping : {
id : null,
user_id : null
},
Metadata
Metadata
Assignees
Labels
No labels