1

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

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
dbinott
  • 911
  • 1
  • 11
  • 36

1 Answers1

1

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>
Chris Peters
  • 17,918
  • 6
  • 49
  • 65
  • I was really hoping this would work, but alas, it does not save my checkboxes still. – dbinott Mar 28 '12 at 15:53
  • Here is the dump of params when trying to update ![CF Dump](http://i369.photobucket.com/albums/oo140/dbinnc/3-28-201211-33-18AM.png) – dbinott Mar 28 '12 at 16:35
  • See my questions in the EDIT above. – Chris Peters Mar 29 '12 at 11:52
  • here is the output of the first question ![Output #1](http://i369.photobucket.com/albums/oo140/dbinnc/3-29-201211-12-33AM.png) and yes, I am getting an error "Please provide a value for pet type", but there is no such form field. And I thought I was not making it check when I did this update. – dbinott Mar 29 '12 at 16:13
  • I just looked at that first output, the petid and eventid in petEvents are reversed. where is that set? – dbinott Mar 29 '12 at 16:30
  • i found it. was in the hasmanycheckbox keys attribute. just reversed it. Thanks Chris! – dbinott Mar 29 '12 at 16:56