Sam
Sam

Reputation: 14586

breeze: optional custom validator

I have the following data structure:

I have a custom validator that checks if the Contact collection is not empty before saving a Job entity. It works fine.

In another part of the application I load my Task entities from the database along with the Job entities (but without the Contact entities as they are not required in this part of the application).

The user makes some modification to a Task entity as well as to one of the Job entities belonging the Task. Then when the user hits the save button, it fails because the custom validator throws an error since there are no Contact entities in the collection.

How do I handle this scenario ? Basically the custom validator should not trigger here, but how do I know when to call it or not ?

I hope this makes sense ?

Upvotes: 1

Views: 44

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

You can use the EntityAspect.isNavigationPropertyLoaded method (see: http://www.breezejs.com/sites/all/apidocs/classes/EntityAspect.html#method_isNavigationPropertyLoaded )

i.e. do not bother performing the validation unless the Job entities are already loaded.

Upvotes: 2

Related Questions