-
Notifications
You must be signed in to change notification settings - Fork 19
Description
Is your feature request related to a problem? Please describe.
When I call the isValid function on my entity instance, it returns true or false, indicating whether or not my entity is valid.
Additionally, this function includes in my entity an errors key containing the errors that were detected in the validation, according to the rules defined in the entity.
However, even when there is no error, it still creates the errors key in the entity, containing an empty object.
This can lead to problems, for example if I pass the already validated entity to another usecase, or if I pass it to some function to insert into the database, which will insert the errors key containing an empty object.
Describe the solution you'd like
I believe we can make a conditional to only insert the errors key if there really is a validation error.
In the baseEntity.js file in the line that follows:
Line 50 in ae6be8e
| this.errors = errors |
Describe alternatives you've considered
I have not considered alternatives to this feature.
Additional context
I noticed on two points:
- By adapting my project that uses herbs2mongo to save nested entities in the database.
- When using a usecase that passes the request it received (entity) to another usecase.
As a temporary fix, after verifying that the entity is valid, I deleted the errors field before calling the other usecase.
delete client.errors;And in the database part, I changed my DataMapper instance to delete keys that I might configure when calling my deletekeys function, as already mentioned in this issue: herbsjs/herbs2mongo#35