HasValidationError returns false for incident and true for incident.Address.
I'll consider checking for validity both incident and incident.Address as a workaround.. because i would have expected for this to work on both main entity and its related entities, maybe the entire object graph. imagine having a class with several [BelongsTo(otherClass)]. Another issue that i discovered, is that when client validation is enabled (jQuery in my case), server validation is not performed anymore. Again i don't find this normal (but this is another discussion). Anyway, thank you for pointing out the entity/entity graph validation issue. Dan On Jul 28, 12:06 pm, Zdeslav Vojkovic <[email protected]> wrote: > if HasValidationError returns true, you are not even getting to the Save > part, right? > In your case, I would expect HasValidationError to return false when Address > fields > are empty, but the incident.Save would be called and throw the error you > mentioned. > This is the expected behavior. Are you saying that this is not happening or > do you > expect something else to happen? > > HasValidationError works on an entity, not on an entity graph (please > someone correct > me if I am wrong). Address is a different entity, so the check is not > propagated (please note > that [Nested] objects are different story). > > You could try something like if ( HasValidationError( incident ) || if ( > HasValidationError( incident.Address ) )) > > > > On Tue, Jul 28, 2009 at 10:54 AM, bdaniel7 <[email protected]> wrote: > > > before tx I check if the instance is valid with: > > if ( HasValidationError( incident ) ) > > { > > Flash["incidentform"] = incident; > > Flash["summary"] = GetErrorSummary( incident ); > > } > > else > > Save > > > the HasValidationError return true and i get a validation error on > > Save/Create: > > "Can't save or update as there is one (or more) field that has not > > passed the validation test" > > > On Jul 28, 11:44 am, Zdeslav Vojkovic <[email protected]> > > wrote: > > > how does you controller code look like? I would expect something > > equivalent > > > to this: > > > > using (TransactionScope tx = new > > TransactionScope(TransactionMode.Inherits)) > > > { > > > Incident i = ... // instantiate a new incident > > > i.Create(); // add it to the session, to be flushed on commit > > > tx.VoteCommit(); > > > > } > > > > in this case, validation should kick in during the saving for all objects > > > which are saved/updated. > > > Are you doing something different? > > > > On Tue, Jul 28, 2009 at 10:18 AM, bdaniel7 <[email protected]> wrote: > > > > > I'm interested mainly in the instance to be validated in the > > > > controller, during save/update operations. > > > > However this doesn't happen either. > > > > > On Jul 28, 11:14 am, Zdeslav Vojkovic <[email protected]> > > > > wrote: > > > > > AFAIK, validation is not propagated to related objects when executed > > > > > explicitly like in your test. > > > > > However, it will be performed during Save()/Update() for each > > > > saved/updated > > > > > object in the graph. > > > > > > IMO, this makes sense because the related object might be lazy > > loaded, so > > > > in > > > > > order to validate it, > > > > > it has to be retrieved from the DB first. > > > > > > On Tue, Jul 28, 2009 at 9:25 AM, bdaniel7 <[email protected]> > > wrote: > > > > > > > Hello, i have the following setup: > > > > > > > [ActiveRecord(Lazy = true, DynamicInsert = true, DynamicUpdate = > > true, > > > > > > SelectBeforeUpdate = true)] > > > > > > public class Incident : ActiveRecordValidationBase<Incident> > > > > > > { > > > > > > Address address; > > > > > > > [BelongsTo(Cascade = CascadeEnum.SaveUpdate, Update=false)] > > > > > > [ValidateNonEmpty(RunWhen = RunWhen.Insert)] > > > > > > public virtual Address Address > > > > > > { > > > > > > get { return address; } > > > > > > set { address = value; } > > > > > > } > > > > > > > //... other props > > > > > > } > > > > > > > [ActiveRecord( Lazy=true, DynamicInsert=true, DynamicUpdate=true, > > > > > > SelectBeforeUpdate=true )] > > > > > > public class Address : ActiveRecordValidationBase<Address> > > > > > > { > > > > > > // all properties are required: street, street nr, city, > > postcode > > > > > > [Property] > > > > > > [ValidateNonEmpty] > > > > > > public virtual string Street > > > > > > { > > > > > > get { return street; } > > > > > > set { street = value; } > > > > > > } > > > > > > } > > > > > > > [Test] > > > > > > public void Validate_Incident() > > > > > > { > > > > > > Incident i = new Incident(); > > > > > > i.Address = new Address(); > > > > > > > CachedValidationRegistry registry = new > > > > CachedValidationRegistry(); > > > > > > ValidatorRunner runner = new ValidatorRunner( registry ); > > > > > > > bool valid = runner.IsValid( i ); > > > > > > Assert.That(valid, Is.False); > > > > > > } > > > > > > > The test fails, meaning that the incident is considered valid, even > > > > > > though the address (or other props) are not filled in. > > > > > > The validation is not performed in the controller either, in a code > > > > > > like this: > > > > > > > public void Save( [DataBind( "incident", Validate=true )] Incident > > > > > > incident ) > > > > > > { > > > > > > ... > > > > > > } > > > > > > > Am i doing something wrong? Is there a bug? This issue is driving > > me > > > > > > crazy... > > > > > > > Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
