-
Notifications
You must be signed in to change notification settings - Fork 12
UsingmodelglueGenericRead
When this message is broadcast, the DataController will attempt to read a specific record from a given table.
This message is configured by using the following tags:
- Object (Required) - The name of the table from which to read.
- RecordName (Optional) - The name of the viewstate value to set the resultant record into. Defaults to Object & "Record".
- Criteria (Optional) - A list of viewstate values to use as filters. Any value listed whose name matches a column in the target table will be used as a filter in the query's WHERE clause. This will most often be set to a list of the table's primary keys. If left empty, a new record will be created.
To perform a basic read on a Contact table, the following tag could be added to an :
<message name="modelglue.GenericRead">
<argument name="object" value="Contact" />
</message>
A View could then the record by performing the following code:
<cfdump var="#viewstate.getValue("ContactRecord")#" />
Note: Because no criteria were specified, this would return a new, empty record.
To perform a basic read on a Contact table and set it into a specific value in the Viewstate, the following tag could be added to an :
<message name="modelglue.GenericRead">
<argument name="object" value="Contact" />
<argument name="recordName" value="myContact" />
</message>
A View could then the record by performing the following code:
<cfdump var="#viewstate.getValue("myContact")#" />
Note: Because no criteria were specified, this would return a new, empty record.
To perform a basic read of a Contact record that would filter on the viewstate's current ContactId value, the following tag could be added to an :
<message name="modelglue.GenericRead">
<argument name="object" value="Contact" />
<argument name="criteria" value="ContactId" />
</message>
Assuming an event-handler name of "contact.read", visiting the event handler with the following URL would result in reading a contact with a ContactId value of 42.
index.cfm?event=contact.read&contactId=42