Relation.join behaviour
Closed this issue · 1 comments
join result
On a class that uses FKEYS property, when we use join you have different kind of result depending on how many field names you specify.
Steps to reproduce :
> Class1().join([Class2(), '_foreign', ['id']])
{
...
_foreign: ['my-super-id'],
...
}
> Class1().join([Class2(), '_foreign', ['id', 'label']])
{
...
_foreign: [{
'id': 'my-super-id',
'label': 'helloworld'
}],
...
}
This inconsistency of results may lead to errors.
What I'd advice is to have two join functions with the following signatures :
join([ rel: Relation(), fkey: string, field: string ], ...)
that would give a (field-type) list under the fkey attribute of the result
AND
join([ rel: Relation(), fkey: string, fields: string[], ...)
that would give a dictionary list under the fkey attribute of the result.
fkeys that point to primary keys
A feature that could be interesting would be for foreign keys that point to an id. We could have the "joined" object directly in the property instead of have a list of one object.
join currently doesn't work on reverse fkeys. I've got a patch ready but I need to write some tests before releasing it.