Mark Drew (Redux)- cf_etc...

a compendium of railo, cfml, cfeclipse and technology topics

Mark Drew (Redux)- cf_etc...

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

August 13, 2007 ·

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"

Tags: model-glue

5 responses

  • 1 todd sharp // Sep 22, 2008 at 4:13 PM

    Just to clarify, these are specific to when using an ORM with MG, correct?
  • 2 Mark Drew // Sep 22, 2008 at 4:13 PM

    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
  • 3 udip // Sep 22, 2008 at 4:14 PM

    have you used transfer orm? If so have you done form validations using transfer orm?
  • 4 Mulkazarus // Mar 13, 2009 at 9:25 PM

    <a href=http://www.offersfine.com/rl_cmprwm.php?ct=706z2><size>2]<b>Get your own Nintendo Wii</b></size></a>
    The games console with one of the strangest names on the planet (it's pronounced 'wee') is also one of the most innovative. In fact, with its potential to change the face of the gaming landscape, Wii may be on the verge of a new era, if you'll pardon the pun.
    The $400 Wii package comprises a square white console unit and stand that plugs into your TV or AV receiver, a wireless sensor bar that connects to the console and receives wireless commands from the battery-powered paddle-style Wiimote controller. Basic composite cables are supplied, but if you have a plasma or LCD the $50 component cable options will deliver better picture quality. The console also supports an SD slot, USB port and a DVD drive for games.
    Games data can be saved to SD memory cards, which weren't officially released at the time of publication, but in lieu of their arrival, GameCube memory cards will suffice. The USB port can't be used to save games either, but will enable future hardware upgrades such as a hard drive or DVD player, although no announcements have been made to this effect.
    Despite its DVD drive, the console is not a DVD player (a modification chip is required if you want to watch movies). Nor is it the high definition, hard drive-toting, networked multimedia online multiplayer gaming machine that is the Xbox 360 or forthcoming Playstation 3. Instead, it presents as the most affordable 'next generation' games machine available and, certainly, lacks for no important ingredients if you want to have fun.
  • 5 ogvmlfmo // Jul 25, 2011 at 11:04 AM

    Y9EywK <a href="http://eepqatowdlyh.com/">eepqatowdlyh</a>;, [url=http://zhelmurcxsko.com/]zhelmurcxsko[/url], [link=http://gbshgqkjgkca.com/]gbshgqkjgkca[/link], http://swqdvufgjskm.com/