added error for relatedQueries ommiting 'for' outside subqueries
Hello, recently I came across a weird issue where an insert statement was failing silently, that insert was using relatedQuery without for, so I went through some digging, I found that the foreign key is overridden even if it was included in the insert. through some other digging, I found that lacking .for outside other non-subqueries could result in a not so obvious error, like the one in #1466,
Originally, I thought these were two problems, so I had placed two if statements to check if a target exists or not, one in RelationInsertOperation.js, and the other in RelationOwner.js, and I wrote a quick test, and as I found out, the check in the RelationOwner constructor was able to catch both error conditions, and what I deduced was:
findFirstNonPartialAncestorQuery keeps looking for the first non-partial parent query, my condition checks if that parent even exists, let alone isPartial or not. partial queries that lack a parent at all would never pass this function. this is what causes #1466 in where queries, but the curious thing is that insert statements do not error out here, yet my if statement catches it, I'm not really sure why. If you have a hint as to why I can dig deeper but as this is my first time peeking into Objection's internal I kept my journey short today.
As is though, this doesn't seem to break any other previous tests, and catches my two error conditions.
Coverage decreased (-0.0004%) to 97.063% when pulling 1ca6e675f82f20155c35b098e1ad9497d6000bd5 on Mahamed-Belkheir:master into 1f743815add5ac87eb6c6431f6928434ebbcb3bc on Vincit:master.
@koskimas Maybe should be either merged, or rejected with an explanation why this change is undesired?
@kibertoad I think we should merge this. What's your take on this?