Hi Doug
executeSave() checks isDirty(), but validate() does not.
I'll run through some pseudo code to illustrate what I am talking about:
Perform update on a Contract:
<cfset objContract = reactor.createRecord('contract').load(contractUUID)>
<cfset objContract.setTitle(form.title)>
<cfset objContract.setUserUUID(session.currentUserUUID)>
..etc..
At this point the contract record is loaded and dirty.
<cfif NOT objContract.getUser().getRoles() CONTAINS 'ContractAdmin'
AND objContract.getValue NEQ form.value>
<cfthrow message="Can't change contract value unless you are a
contract admin">
<cfelse>
<cfset objContract.setValue(form.value)>
</cfif>
The objContract.getUser() call loads the User Record and adds it to
variables.children in the Contract Record.
<cfset objContract.validate()>
<cfif objContract.hasErrors()>
... return the user to the form and show validation errors ...
<cfelse>
<cfset objContract.save()>
</cfif>
As I understand it the User Record is not dirty, so it won't be saved,
but it will be validated when objContract.validate() is called.
If the User Record has some issues with it the user will get these
errors when returned to the Contract form.
This specific Contract->User example is not something that we have
encountered, but take for instance a relationship between a contract
and another type of document. There is a rule on the 2nd document type
that the publish date must be GTE now(). We only want that rule
evaluated when we are editing or publishing this document - not every
time it is linked to a new contract.
Does that make it any clearer?
Maybe I've overlooked some feature of the framework that would solve
this for us, but anything that provides us with more granular control
over what get validated would be helpful. At the moment we are having
to do all sorts of gymnastics to work around this.
Cheers
Mark
On 10/4/06, Doug Hughes <[EMAIL PROTECTED]> wrote:
If I'm not mistaken reactor doesn't validate things that aren't dirty. Is
this not the case? IE: if you save and allow for cascading it doesn't save
record that aren't dirty.
Doug
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Mark Stanton
Sent: Tuesday, October 03, 2006 12:08 AM
To: [email protected]
Subject: Re: [Reactor for CF] Recursive Validation
Hi Doug
We have a lot of cases where users fill out a form to create or modify
an object and in the process add, retain or delete relationships to
various other objects.
The validity of these other objects is not in question, they are in
the DB and have already been validated at the point in time when they
were created. Validating them again each time they form a new
relationship makes no sense - we just want to validate their existence
and possibly their status.
A simple (and fairly contrived example) is the relationship between a
Contract object being created and the user who creating it. I don't
the user's password strength checked every time the user submits a new
Contract - and a definitely don't want the form validation to present
a validation message relating to the user's password on the New
Contract form.
Thinking now, it would be great if validate could take a list or array
of relationship aliases that we wanted validated. If this attribute
was missing then the current greedy validation could take place.
Cheers
Mark
--
Mark Stanton
Gruden Pty Ltd
http://www.gruden.com
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--
Mark Stanton
Gruden Pty Ltd
http://www.gruden.com
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --