Yii 1.1: mwbmodelcommand

Batch model class generation with relations from MySQL workbench mwb file

This is a Yii shell command to help generate model classes with relations descriptions.

If you use MySQL workbench for your database design, and have all the relationships defined on the diagram, this will help you to translated them into Yii model classes. So you can always maintain your database schema and relationships in the visual way, and not worry about create or update relations in model class files.

And it's a batch process, which read all the tables from the database connection, and parse the mwb file for corresponding relationships and create the model class file instantly.

It doesn't require innodb, so long as you've got relation on the ERD, it should work for you, and it can tell 1:1,1:M and M:M relationships.




  • Yii 1.0 or above
  • MySQL Workbench 5.0 or above
  • PHP 5 with zip and simplexml enabled


  • Extract the release file under 'framewok/cli'
  • It should not overwrite any original Yii Framework file

We have developed it under the framework purely because it's not project specific and should be available to any newly created projects.


At Yii shell,

> mwbmodel [mwb-file]

This command generates model classes with relationships parsed from MySQL workbench mwb file. * mwb-file: required, mwb file.

Change Log

February 17, 2009

R2404 Minor Bug Fix Release
Fixed file path with backslash problem on windows platform

February 6, 2009

R2402 Bug fix release, tested with 1.0.2
Works better with composite keys (PK with more than one field)

February 5, 2009

R2393 Initial beta release.

Total 9 comments

#1507 report it
skyblaze at 2009/07/10 04:49pm
Yii already does it

now also yii itself can automatically generates model files with relations already defined in the model class based on the db table

#1554 report it
Alexandrino at 2009/06/25 03:24pm
You are the guy!

Thanks so much!!!

#1619 report it
schmunk at 2009/06/01 08:08pm
Works also fine as extension

I just placed the extracted file in 'extensions' and configured my yiic like this:

    // other commands
        'username' => 'root',
        'password' => 'pass'',
#1642 report it
skyblaze at 2009/05/27 04:53am
Model class files updates...

The problem is that every time i execute this cli command (for example 'cause i have a new model class file) the script reread every model in my mysql workbench file and ok it tells me if i want to overwrite an existing model class file but what if i want the cli command to update only my relationships in my model class file without overwrting all my custom code in it?

#1763 report it
luke at 2009/04/13 02:05am
A complete necessity

Hi there,

Would like to say thanks for this extension. Would really love to see this extension able to translate mysql workbench views.

Keep up the good work

#1809 report it
investor at 2009/03/27 01:33pm
It's Great!

This is what I have been looking for. Thanks!

#1877 report it
jorgephantom at 2009/02/05 01:45pm
Exelent tool

I been waiting for something like that, this help me very much.

#1878 report it
qiang at 2009/02/05 01:14pm
Wonderful tool

This should be very useful for large systems with many related tables. It is also a good example of yiic command implementation. Thanks!

#1879 report it
letscode at 2009/02/05 07:37am

Looks great!

Thanks for your work, I will try it soon

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: New BSD License
  • Developed by: unikly
  • Category: Database
  • Votes: +10 / -1
  • Downloaded: 2,543 times
  • Created on: Feb 5, 2009
  • Last updated: Jul 29, 2009