Skip to content

UsingmodelglueGenericRead

dskaggs edited this page Nov 12, 2012 · 1 revision

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:

  1. Object (Required) - The name of the table from which to read.
  2. RecordName (Optional) - The name of the viewstate value to set the resultant record into. Defaults to Object & "Record".
  3. 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.

Examples

A Basic Generic Read

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.

Customizing the Viewstate value name

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.

Reading a Specific 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

Clone this wiki locally