angular-restmod
angular-restmod copied to clipboard
Cannot assign value to hasOne
Attempting to $save() with the proper model object or just the id in the hasOne attribute never gets posted.
.factory('Contact', ['restmod', function(restmod){
var model = restmod.model('api/contact').mix({
});
return model;
}])
.factory('Staff', ['restmod', function(restmod){
var model = restmod.model('api/staff').mix({
contact: { hasOne: 'Contact' },
});
return model;
}])
newStaff = $build({contact:myContact});
newStaff.$save();
Whether I use the Contact restmod object or just the id - contact is never posted.
Cheers!
If you need to send the Contact id when the Staff record is saved then you should use a belongsTo
association instead.
Cheers @iobaixas I have the Contact object belongsTo is not working as expected - although I could be missing something. In fact if I remove the hasOne relationship - it doesn't seem to matter if the staff: {belongsTo:'Contact', key:'contact'} is present or not.
While the Staff create/post works Update/put throws me an error on the server as it's expecting contact as an id, not an object Also causes issues when I get Staff - with hasOne relationship the child Contact is setup as restmod object
The logic is: a Staff has one Contact. There is also many others people types that have one Contact.