Flex on Rails not a dream any more!!!
Have you played with Ruby on Rails? if not well theres no helping you….. (just jokes). But there are alot of nice features. Today lets take a look at ActiveRecord. What it does is on startup of the website it maps database tables to the Class objects (Models in MVC) in its code. From there on in you have methods like Cat.find(:all) which will go find all the cat rows in the Cats table database and return them. Thats it no more code!! How about matching to sql conditions? Well, Cat.find(:first, :collar_color => 'blue'). nice!!
So how cool would it be if flex could do this to a database. Well Mark from WebOrb showed me it can. With that little code!!! Mark has basically mapped alot of the cool functionality of ActiveRecord from ROR into their Flex Data Services package. Very cool! Ok so where is it? Well its still in the works but very close and you will be able to add code like:
<mx:DataGrid dataProvider="{ActiveRecords.Order.findAll()}">
<mx:columns>
<mx:DataGridColumn dataField="OrderID" />
<mx:DataGridColumn dataField="CustomerName" />
<mx:DataGridColumn dataField="BillDate" />
<mx:DataGridColumn dataField="ShipDate" />
</mx:columns>
</mx:DataGrid>
What this basically is, is a data grid that will ask ActiveRecord to go and find all the Orders in the database, and populate the datagrid with them. Hang on i hear you say….what about Async callbacks, when the data has loaded. Well seeing databinding is available in flex that method can return an empty Array collection and when the data is recieved the datagrid will update. No more addEventListener(……… But dont worry you still have them there for use if you want to update the UI. But its AMF packets here so the packets are binary data and pretty quick.
Ok cool so what about all those Order objects we have in the datagrid, what can they do now? Well through the majick of data binding and ActiveRecord you can just have another datagrid below that updates automatically as items are selected in the first:
<mx:DataGrid dataProvider="{otherDataGrid.selectedItem.addresses}">
<mx:columns>
<mx:DataGridColumn dataField="OrderID" />
<mx:DataGridColumn dataField="OrderDate" />
<mx:DataGridColumn dataField="RequiredDate" />
<mx:DataGridColumn dataField="ShippedDate" />
</mx:columns>
</mx:DataGrid>
And that would populate the second datagrid with all the addresses for an order for each click on the first datagrid. And thats all info in the database.
So how does it work? Well you set up your database model as you would any other application, hit the WebOrb Control panel and allow it to inspect the database tables. It will then generate a code base for you to place in your Flex application. Dont worry there are empty stubs for extending with your own functionality which never get over-written when you update the generated code.
Much much much more cool things are in the pipline but this blog post is getting a tad long. So heres what you need to start to find out more information
Also if your lucky enough to be going (or even have tickets too) Flex 360:
"Also, if you are attending the 360Flex conference, I will be demonstrating WDMF during my session next Monday between 4:00 and 5:20 in the Integration track." – Mark Piller
Stay tuned I will be updating with more soon.
