-
Notifications
You must be signed in to change notification settings - Fork 643
Description
Using Objection 2.1.3
This was a bug in my code, but the way Objection handles extra properties in ManyToManyRelations made it hard to track down.
Per the docs, extra is expected to be an array, even if it's an array of length 1, but if we look at https://github.com/Vincit/objection.js/blob/master/lib/relations/manyToMany/ManyToManyRelation.js#L413 we see that if it's not an array it gets treated as an object and there's some extra handling that happens.
The problem I ran into was that if your relation definition has extra: 'myExtra' instead of extra: ['myExtra'] Objection will happily consume 'myExtra' and treat the letters of the string as individual extra elements(Object.keys() on a string will convert the string into an array of chars), so it tries to fetch "Table"."e", "Table"."x", "Table"."t"... and you wind up with an error and a very confusing looking query.
It seems like a string literal instead of an array could be treated as an error here to prevent others from shooting themselves in the foot as I did. Happy to take a stab at a PR, but I don't understand the use case represented by the object processing, so I'm not sure if a simple check is going to do the trick.