| | 1 | = Using modelglue.!GenericRead = |
| | 2 | |
| | 3 | When this message is broadcast, the !DataController will attempt to read a specific record from a given table. |
| | 4 | |
| | 5 | This message is configured by using the following <argument> tags: |
| | 6 | |
| | 7 | 1. Object (Required) - The name of the table from which to read. |
| | 8 | 1. !RecordName (Optional) - The name of the viewstate value to set the resultant record into. Defaults to Object & "Record". |
| | 9 | 1. 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. |
| | 10 | |
| | 11 | == Examples == |
| | 12 | |
| | 13 | === A Basic Generic Read === |
| | 14 | |
| | 15 | To perform a basic read on a Contact table, the following <message> tag could be added to an <event-handler>: |
| | 16 | |
| | 17 | {{{ |
| | 18 | <message name="modelglue.GenericRead"> |
| | 19 | |
| | 20 | <argument name="object" value="Contact" /> |
| | 21 | |
| | 22 | </message> |
| | 23 | }}} |
| | 24 | |
| | 25 | A View could then <cfdump> the record by performing the following code: |
| | 26 | |
| | 27 | {{{ |
| | 28 | <cfdump var="#viewstate.getValue("ContactRecord") /> |
| | 29 | }}} |
| | 30 | |
| | 31 | Note: Because no criteria were specified, this would return a new, empty record. |
| | 32 | |
| | 33 | === Customizing the Viewstate value name === |
| | 34 | |
| | 35 | To perform a basic read on a Contact table and set it into a specific value in the Viewstate, the following <message> tag could be added to an <event-handler>: |
| | 36 | |
| | 37 | {{{ |
| | 38 | <message name="modelglue.GenericRead"> |
| | 39 | |
| | 40 | <argument name="object" value="Contact" /> |
| | 41 | |
| | 42 | <argument name="recordName" value="myContact" /> |
| | 43 | |
| | 44 | </message> |
| | 45 | }}} |
| | 46 | |
| | 47 | A View could then <cfdump> the record by performing the following code: |
| | 48 | |
| | 49 | {{{ |
| | 50 | <cfdump var="#viewstate.getValue("myContact") /> |
| | 51 | }}} |
| | 52 | |
| | 53 | Note: Because no criteria were specified, this would return a new, empty record. |
| | 54 | |
| | 55 | === Reading a Specific Record === |
| | 56 | |
| | 57 | To perform a basic read of a Contact record that would filter on the viewstate's current !ContactId value, the following <message> tag could be added to an <event-handler>: |
| | 58 | |
| | 59 | {{{ |
| | 60 | <message name="modelglue.GenericRead"> |
| | 61 | |
| | 62 | <argument name="object" value="Contact" /> |
| | 63 | |
| | 64 | <argument name="criteria" value="ContactId" /> |
| | 65 | |
| | 66 | </message> |
| | 67 | }}} |
| | 68 | |
| | 69 | 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. |
| | 70 | |
| | 71 | index.cfm?event=contact.read&contactId=42 |