angular-restmod
angular-restmod copied to clipboard
inline reference relations with same key as attribute name clobbers inline resource
Imagine we want:
Person:
restmod.model('/people').mix({
parent: {
belongsTo: 'Person',
key: 'parent'
}
})
So we can support either:
// GET /people/mom
{
id: "mom",
parent: "grandma"
}
or
// GET /people/mom
{
id: "mom",
parent: {
id: "grandma"
}
}
Inline resources in responses like this like this seem to get clobbered. Am I the only one?
Maybe I should change my API -- should I? -- but it seems to me that this use case should work nevertheless.
Edit: Mongoose supports this kind of behavior by default.
I have the same question!
There seems to be a bug in restmod when using the same value for key
as the association name, it tries to handle the key as inline data for the nested object and it breaks, I'll take a look into that.
I'm not sure if the behaviour you propose is possible though, restmod need to know in advance wether an attribute is a key or a nested object...
Hi @iobaixas
In mongoose we can test if a field is populated with isPopulated()
function. Here we might be able to test so by looking for the $pk
field, and if it doesn't exist then the item is unpopulated, and restmod can proceed to populate it.