Open TissuePowder opened 2 years ago
@TissuePowder it looks like only the table names are validated. Likely, that's all objection knows about (via tableName
).
Have you verified that related columns are validated? I suspect they aren't and would require some kind of table introspection outside of Objection itself.
I have two objectionjs models,
Meal
andMealType
that correspond tomeal
andmeal_type
tables respectively in the database. I defined a relationship as follows, whereMeal
is the owner model andMealType
is the related model.Now in the
join
object, if I misspell the name of the related table, or change a case, the error is caught while querying the model. For example, if I doto: 'mealtype.id'
, (notice the smallt
instead ofT
) I get the following error:"Meal.relationMappings.mealType: join: either `from` or `to` must point to the owner model table and the other one to the related table. It might be that specified table 'mealtype' is not correct"
That's great, but if I misspell anything in the owner table, like if I write
from: 'meal.MealTypeId',
(notice theM
instead ofm
) I don't get any kind of error. Just, during theMeal.query().withGraphFetched('mealType')
query, the returned data ofmealType
isnull
.I personally did a spelling mistake on the owner table's field-name and it took some time to understand where the problem was. So if possible, can we have some kind of validity checking on the owner table as well?
I am using
objectionjs 3.0.1
andpostgres 14.3
. I am also using...knexSnakeCaseMappers()
inknexfile.js
.