Description
versions:
"js-data": "2.8.2",
"js-data-angular": "3.1.0",
Hi there! I have a model that looks like this:
{
name: 'TelephoneNumber',
endpoint: 'telephonenumber',
relations: {
belongsTo: {
Account: {
parent: true,
localKey: 'accountId',
},
Partition: {
parent: true,
localKey: 'partitionId',
}
}
},
}
As you can see a TelephoneNumber
belongs to both an Account
and Partition
(incidentally, an Account
belongs to a Partition
). Odd, I know. When I call getEndpoint
like so:
const item = {accountId: 'foo', partitionId: 'bar', ...otherStuff}
const url = httpAdapter.getEndpoint(TelephoneNumberDefinition, item)
Here this returns: partition/bar/telephonenumber
The issue is that right now the defineResource
method doesn't support having a definition with multiple parent
, parentKey
, and parentId
properties (here. So when that runs the account is set as the parent, and then the partition overrides it (though this is not 100% deterministic because iteration on objects is not 100% consistent across browsers).
What I would expect is if I provide an accountId
it should factor the account
in generating the URL, so it would become: partition/bar/account/foo/telephonenumber
Problem I can see from this is with me providing both an accountId
and a partitionId
, you don't know which one to use... So, I think maybe the solution could be that I don't provide a partitionId
and you look that up on the account
which would happen naturally...
To sum up, what I think needs to happen is this code needs to account for multiple parents. Then all code using that needs to account for a potential of an array of parents (in particular, the getEndpoint
method). That would resolve my issue...
I expect that this would be a breaking change for people depending on and using the parent
with multiple belongsTo.