Thanks Teddy

I'm definitely not feeling patronised - far from it, I really
appreciate your input.

I'm especially interested in your statement about the error collection
not being an exception handler. This is my first time working with
reactor, but in past projects I have generally had a similar system
of:
- being able to run a generic validate method against all objects and
- having a set of custom rules executed and
- having a structure containing error details returned

I guess when I first saw the validation behaviour in reactor it felt
familiar so I have jumped to some conclusions about how it worked. I
would still like to use validate() and the error collection as my
primary means of trapping and dealing with data validation errors in
my Record objects if it is up to the task, but I'll keep your warning
in mind.

Well because of the link you created in your reactor.xml, the Agency object
will be valdiated as well as a member of Contract.

That doesn't make sense to me - in my model we have a relatively small
number of fairly static agencies, contracts on the other hand are
created regularly. In this case I am creating a contract, the agency
that a contract belongs to  may not have changed for years.

However if reactor was loading the linked agency and then validating
it, that would make some sense, but its not - its trying to validate
an empty agency.

The error collection for the parent object did not return anything probably
because it did not have errors.  Because of the child object relationship,
the error collection found errors with member child object.

This is correct - the ContractRecord itself did not have any
validation errors, but ContractRecord.hasErrors() was returning true.


When you validate the objContractRecord, the errors can be address from
getting the member functions's error collection.

 <cfset objContractRecord.validate()>
<cfset objAgency = objContractRecord.getAgency ()>
<cfset ercAgency = objAgency._getErrorCollection()>

But as soon as I do getAgency the AgencyRecord is loaded out of the
database and the errors disappear.


Cheers

Mark


On 7/25/06, Teddy Payne <[EMAIL PROTECTED]> wrote:
Well because of the link you created in your reactor.xml, the Agency object
will be valdiated as well as a member of Contract.

The error collection for the parent object did not return anything probably
because it did not have errors.  Because of the child object relationship,
the error collection found errors with member child object.

When you validate the objContractRecord, the errors can be address from
getting the member functions's error collection.

 <cfset objContractRecord.validate()>
<cfset objAgency = objContractRecord.getAgency ()>
<cfset ercAgency = objAgency._getErrorCollection()>

When you create the <hasMany> Agency falls within the validation.  Errors
can be anything from missing data to badly formed data.

The error colelction is there to warn you of negative behaviors.  Obviously
some errors need more attention, but the error collection in my vision is
not meant to be an exception handler.  I see it as a way to warn me possible
programmatic issues before I try and use the create data objects.

I am not trying to state the obvious or patronize anyone here.


Teddy

On 7/25/06, Mark Stanton < [EMAIL PROTECTED]> wrote:
> Thanks Teddy
>
> I understand that relationship but I'm still not sure about the
> validation behaviour. Why is one object causing the implicity
> validation of the other? It's not even loading the related object
> before validating it.
>
> Mark
>
> On 7/25/06, Teddy Payne < [EMAIL PROTECTED]> wrote:
> > Well, all of your questions stem from your Reactor.xml declaration.
> >
> > Based upon your reactor.xml, when you execute
> >
> >
> > <cfset objContractRecord =
> > variables.objReactor.createRecord('Contract')>
> >
> > Now because of your linking rector.xml you can now have:
> >
> > <cfset qryAgency =
> > objContractRecord.getContractIterator().getQuery() />
> >
> > or
> >
> > <cfset arAgency =
> > objContractRecord.getContractIterator().getArray() />
> >
> > This allows you to show all the associated Agencies for a Contract in a
nice
> > neat array or query.
> >
> > Teddy
> >
> >
> >
> > On 7/25/06, Mark Stanton <[EMAIL PROTECTED]> wrote:
> > > Hey All
> > >
> > > I've got a curly one....
> > >
> > > My reactor.xml has:
> > >
> > > <object name="Agency">
> > >         <hasMany name="Contract">
> > >                 <relate from="AgencyUUID" to="AgencyUUID"/>
> > >         </hasMany>
> > > </object>
> > > <object name="Contract">
> > >         <hasOne name="Agency">
> > >                 <relate from="AgencyUUID" to="AgencyUUID"/>
> > >         </hasOne>
> > > </object>
> > >
> > > I have some code that creates a new contract...
> > >
> > > <cfset objContractRecord =
> > variables.objReactor.createRecord ('Contract')>
> > >
> > > <cfset objContractRecord.setContractUUID
(createUUID())>
> > > <cfset objContractRecord.setAgencyUUID(arguments.agencyUUID)>
> > > <cfset objContractRecord.setStartDate (arguments.startDate)>
> > > <cfset objContractRecord.setEndDate(arguments.endDate)>
> > > <cfset objContractRecord.setValue(arguments.value)>
> > > <cfset
> > objContractRecord.setDescription
(arguments.description)>
> > >
> > > <cfset objContractRecord.validate()>
> > >
> > > <cfif NOT objContractRecord.hasErrors ()>
> > >         <cfset objContractRecord.save ()>
> > > </cfif>
> > >
> > > ...but hasErrors() is returning true.
> > >
> > > ...but
> >
objContractRecord._getErrorCollection()_getErrorsTranslated()
> > > is returning an empty array.
> > >
> > > So where is my error?
> > >
> > > I ended up digging into the hasErrors() method of the abstractRecord
> > > object and found that it checks children as well as the current object
> > > (not sure I like that idea, but anyway).
> > >
> > > So I create a getChildren() method in my ContractRecord and run the
> > following:
> > >
> > > <cfset children = objContractRecord.getChildren ()>
> > > <cfloop collection="#children#" item="child">
> > >         <cfdump
var="#children[child].validated()#"><br>
> > >         <cfdump
var="#children[child].hasErrors()#"><br>
> > >         <cfdump
> >
var="#children[child]._getErrorCollection().getTranslatedErrors()#"><br>
> > >         <cfdump var="#children[child]._getTO()#"><br>
> > > </cfloop>
> > >
> > > From this I can tell:
> > > * I have one child, an AgencyRecord object
> > > * children[child].validated() is true
> > > * children[child].hasErrors() is true
> > > *
> >
children[child]._getErrorCollection().getTranslatedErrors()
> > returns
> > > a number of errors
> > > * children[child]._getTO() returns an EMPTY AgencyTO
> > >
> > > I scratch my head, go have some lunch and when I get back I add one
> > > line to my code:
> > >
> > > <cfset objContractRecord.getAgency()>
> > >
> > > ..just before the <cfset objContractRecord.validate()>
> > >
> > > Now everything works - no validation errors.
> > >
> > > All of this has me stumped for a number of reasons:
> > >
> > > - Why is an child AgencyRecord getting checked when I validate a
> > ContractRecord?
> > > - When it fails why does it fail silently? Could it not report the
> > > problem to the ContractRecords ErrorCollection?
> > > - Why is my AgencyRecord reporting that it has been validated? I
> > > certainly didn't run validate() on it (I didn't even know it was
> > > there). Maybe _setErrorCollection() is being called on it somewhere
> > > during instantiation?
> > >
> > > Anyway sorry for the rant and thanks in advance for any advice.
> > >
> > > --
> > > 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/
> > > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
> > -- --
> > >
> > >
> >
> >
> >
> > --
> > <cf_payne />
> > http://cfpayne.wordpress.com/
> >
> > -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
--
> > -- --
> > 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/
> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
>
>



--

<cf_payne />
 http://cfpayne.wordpress.com/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
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/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply via email to