Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating navigation properties, bug or feature?

Tags:

breeze

I am having problems with the validation of navigation properties. I do not know if it's a bug or just does not work as I expected.

When you have a navigation property required with his foreign key (in my case int type) is successfully added the validator and, as an int can not be null, is assigned the default value 0, but when the entity is being validated, as the property has value (0), is given as correct. I expected that the entity was not valid.

Is it a bug or correct behavior?

Greetings.

like image 621
Julián Yuste Avatar asked May 01 '26 19:05

Julián Yuste


1 Answers

It is a good question. I don't think this is a bug or a feature. Nor would I consider an async validation option.

Instead, I would add a custom validation on the FK (or the property) that declared that the FK property is invalid when it is 0. Yes, that means the entity is in an invalid state at the moment of creation. Nothing can be done about that. You're using '0' as a sentinel value that means "I don't know yet". The validation means "... and the entity is invalid until I know."

Btw, Breeze cannot assume that 0 is invalid. That could be a valid FK to the related entity.

This problem isn't unique to FKs. You have it when creating a new order lineitem with 'quantity=0' and your business rules say it must be >0. The type requires you to specify SOMETHING and yet you cannot provide the correct answer a priori. Again, Breeze can't assume that '0' is a bad value. You have to specify that.

There is no bug per se in either scenario. Both require additional developer attention to "do the right thing".

like image 151
Ward Avatar answered May 06 '26 02:05

Ward