best cricut

mwbModelCommand, Yii Framework and MySQL Workbench

In the past few weeks we have been exploring with Yii Framework, and two of us have started porting some of our project to Yii Framework. One of the first few things that caught our attention is the CActiveRecord model classes, which require relational rules to describe relationships among database tables. We are glad that Yiic can help to create project scaffolds and create controller, model and CRUD, however it's not very practical to manually add all the relationship if your project has over 10 tables.

Our normal practice prefers to design database with relational diagram, so it not only sets out the table schemas but also visually demonstrates the relationship of database tables. However in this fast changing world, without the right tool most the relational diagram tends to out of sync with real production database. For most the of our project, we create ERD and generate database from the diagram in the design phase and later on in the development phase, most the developer choose to update the schema on the table directly, since that's quick, and most of them don't have the habit to update the ERD with relavant changes. You will feel lucky if your database design tool comes with reverse engineering, which can help you syn with your database at a later point still, otherwise you'll be purely rely on your bare eye and hand to syn among database table your model classes and the ERD.

So I believe when it comes to database design it should always be diagram driven, therefore if there's any changes need to be made, always update the digram first and carry on to your physical table and model class. Although we are still looking for good database migration tools to manage schema diffs. We have written a little script to help Yii Framework to work with MySQL Workbench (which we use to model MySQL databases), the purpose of the script is to batch create model classes for Yii Framework (although Yiic can generate models one by one, we want it happen at once and for all), and with the help of mwb file it can create the relational rules for the models, so there's no manual translation needed while you creating the models. Since it's a Yii shell command, we have named it 'mwbModelCommand'.

It's available for download at this Yii Extensions page, or Yii Framework mwbModelCommand (direct link)

Hope this script will save your time on relational model creation, if anyone have issues or suggestions mwbModelCommand please feel free to post back.

Wish List (Todo),
A tool (set) to stream line the database migration, so it would not only creates the models, but may also update (revert) models as well as database table schema at once, and data safe if possible. Please advice if you know something good out there.

Be Sociable, Share!


  • Hi,

    I posted links to your blog on the MySQL Workbench forums.

    See the Workbench plugins to autogenerate schemas for Propel, Doctrine, Symfony. Would you be able to contibute a plugin to autogenerate schemas for Yii/CActiveRecord?,208229

    MySQL Workbench Team

    • Frank Liu says:

      Hi Edwin,

      Thanks for you interest and support.

      To my understanding that Yii CActiveRecord does not need any schema file to work with, it reads the schema on the fly from the database table structure. And with Yii shell command it helps to generate the CActiveRecord class files, but without relational rule, so our script simply fills this gap by utilizing mwb file, which should help on medium/large scale database driven web applications.

      Therefore it should work as Yii plugin rather than a MySQL workbench plugin, where it would fit the purpose and context more.

      However we’ll look into workbench plugins, and see if we can come up with some useful tools to help web development with MySQL workbench.


  • johnpupu says:

    Hi, Thx for your sharing
    but it doesn’t work on Yii 1.0.9

  • Any news on the functionality to update existing tables, by injecting just new rules, rather than overwrite them? What about reverse engineering, i.e. in the case a developer manually changed some rules, added some tables and models?

RSS feed for comments on this post.

Copyright Orite Group Pty Ltd | Powered by WordPress | Theme: Aeros 2.0