Hey,

 

I’m fairly new to reactor and have started to play around with cascading saves, and validation.  I assumed that validate() cascades like save(), and after looking in reactor\base\abstractRecord.cfc it appears it does cascade validation, in the afterValidate function.  But it doesn’t appear to add the children’s validation errors to the parent’s errorCollection.  I find this to be a bit odd, since we are doing a cascading save, why would the validate not cascade and all the errors be in one central location? 

 

 

For the curious here is the relevant code:

I’m using model-glue and the newest svn checkout of reactor.

 

 

Relevant parts of Reactor.xml:

 

<object name="pcard">

                        <hasMany name="meal">

                                    <relate from="pcard_id" to="meal_pcard_id" />                                        

                        </hasMany> 

</object>

 

<object name="meal">

              <hasOne name="pcard">

                          <relate from="meal_pcard_id" to="pcard_id" />

              </hasOne>

</object>

 

Relevant Code:

 

<cfset var pcardRecord = variables.Reactor.CreateRecord("pcard") />

<cfset var mealRecordArray = ArrayNew(1) />

<cfset var errorCollection = "" />

 

<!--- auto populate form data into a bean using makeEventBean --->          

<cfset pcardRecord = arguments.event.makeEventBean(pcardRecord) />

 

<!--- Create meal record(s) --->

<cfloop from="1" to="12" index="i">

            <cfif arguments.event.getValue("meal_name#i#") NEQ "">

                        <!--- Add a record to the mealRecordArray. --->

                        <cfset arrayAppend(mealRecordArray,pcardRecord.getMealIterator().Add()) />

                        <cfset mealRecordArray[i].SetMeal_Name(arguments.event.getValue("meal_name#i#")) />

                        <cfset mealRecordArray[i].SetMeal_Affil(arguments.event.getValue("meal_affil#i#")) />

                        <cfset mealRecordArray[i].SetMeal_Pcard_id(pcardRecord.getPcard_id()) />

            </cfif>

</cfloop>

 

<cfset pcardRecord.validate() />

<cfset errorCollection = pcardRecord._getErrorCollection() />

           

<cfif IsDefined("ErrorCollection") AND ErrorCollection.hasErrors()>

            <!--- output errors --->

<cfelse>

            <!--- Save Pcard and meal records --->

            <cfset pcardRecord.Save() />

</cfif>

 

 

Ryan Blatz


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[email protected]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply via email to