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/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
