Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many to Many Extra property parsing - more informative error handling. #1703

Closed
mattboutet opened this issue Mar 4, 2020 · 2 comments
Closed

Comments

@mattboutet
Copy link

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.

@koskimas
Copy link
Collaborator

koskimas commented Jun 8, 2020

Yep, makes sense.

@koskimas
Copy link
Collaborator

koskimas commented Jun 8, 2020

Fixed by handling a string as an extra name as one would expect. Other people have made this mistake too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants