Question

I am trying to figure out how can I update the petevents table with several events. I get no error, but it is also not updating/inserting. Here are the relevant code snippets and the schema for the relevant tables follows.

View

<cfloop query="events">

#hasManyCheckBox(objectName="pet",

association="petevents",

keys="#pet.key()#,#events.id#",

label=events.eventname)#

</cfloop>

Pet Model

<cfset hasMany(name="petEvents", dependent="deleteAll", shortcut="events")>
<!--- nested properties --->
<cfset nestedProperties(associations="petEvents", allowDelete=true)>

Event Model

<cfset hasMany(name="petevents", dependent="deleteAll")>

PetEvent Model

<cfset belongsTo("pet")>    
<cfset belongsTo(name="event", joinType="outer")>

View Update in Controller

<cfset pet = model("pet").findByKey(key=params.key)>
<cfset pet.update(params.pet)>

Schema pertaining to relevant tables

EDIT: I change the validatesPresenceOf property "when" to oncreate only. Then I saved and got this error. "Duplicate entry '1025-1025' for key 'PRIMARY'"

Thanks,

Derek

Was it helpful?

Solution

In your controller, don't forget to include petEvents:

<cfset pet = model("pet").findByKey(key=params.key, include="petEvents")>

EDIT:

In response to your dump below, can you tell me what you get when you do this in your update action?

<cfset pet = model("pet").findByKey(key=params.key, include="petEvents")>
<cfset pet.setProperties(params.pet)>
<cfdump var="#pet#" abort>

If that appears to be fine, what happens when you do this? Any errors?

<cfset pet = model("pet").findByKey(key=params.key, include="petEvents")>
<cfset pet.setProperties(params.pet)>
<cfset pet.update()>
<cfdump var="#pet.allErrors()#">
<cfloop array="#pet.petEvents#" index="petEvent">
    <cfdump var="#petEvent.allErrors()#">
<cfloop>
<cfabort>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top