Aug 13 2007

Model Glue Tips Part 4: Use Generic Database Messages to speed up your development

Posted by Mark Drew at 9:06 AM
3 comments
- Categories: model-glue

A lot of the time that you are developing an application, depending on how you have set up your database etc, you will want to do a "select * from sometable", for example to get the types of pages you have, or a full list of user roles or simply to get the current user. This is all fine if you are sticking to the semi rigid pattern of having services for your whole architecture, but in the heat of battle, you might be tempted to do a cfquery in your view. DONT! Model-Glue gives you a built-in way of doing Generic Database actions (or messages as they are called in the documentation) The messages that you can call from the broadcast section of your event handler are:
  • modelglue.GenericList: Which does a select * from [table]
  • modelglue.GenericRead: Which does a select * from [table] where [id] = xyz
  • modelglue.GenericCommit: Which will save the record (or update it depending if it already exists with that ID)
  • modelglue.GenericDelete: Which will delete the record with the ID that you have passed in
An example of using modelglue.GenericList would be to list the People in our fictional system. In ModelGlue_people.xml I create an event-handler to display people: <event-handler name="people.list.users">
      <broadcasts>
         <message name="modelglue.GenericList">
            <argument name="object" value="People" />
            <argument name="queryName" value="qPeopleList" />
         </message>
      </broadcasts>
   
      <view>
   </event-handler>
Then in my display template I can get access to the query: <cfdump var="#viewstate.getValue("qPeopleList")#"/> There is more functionality available such as filtering and sorting, you can check out the details in the Documentation for modelglue.GenericList Calling the other other Generic Database functions is as simple as that, have a look at the full documentation over at http://docs.model-glue.com/ under "How To's" / "How To Use Generic Database Messages"

Comments

todd sharp

todd sharp wrote on 09/22/08 11:13 AM

Just to clarify, these are specific to when using an ORM with MG, correct?
Mark Drew

Mark Drew wrote on 09/22/08 11:13 AM

Yeah, you need to have an ormservice defined in the coldspring.xml file, be it Transfer or Reactor since ModelGlue then uses the ORMService to do these functions.

Its a nice split and a great demo of very configurable functions in your CMS
udip

udip wrote on 09/22/08 11:14 AM

have you used transfer orm? If so have you done form validations using transfer orm?

Write your comment



(it will not be displayed)







Search Archives

Contribute


Twitter Updates

Categories

coldfusion cfeclipse personal apple cfconferences webdev model-glue ukcfug blogging cfunited coldspring presentations adobe scotch on the rocks cfobjective lost reactor jobs flex eclipse ajax model-glue frameworks max reference google podcasting fusebox ask md spam railo eventvalidation donations tattoo snipex podcast music microsoft fusiondebug flying blue dragon air wishlist tips rant open bluedragon java graphic novels funny eventguard derby blog aptana apple xml webservices transfer tashr subversion spry regex quack pownce ooops mvc metrics jquery itunes hosting groovy gadgets flash firefox doh! directing development coldfusioncamp codeshare cfug cfonwheels cfdevcon bolt apollo

Monthly Archives