[EXTENSION] mwbmodelcommand discussion thread

Just thought to create this main thread for mwbmodelcommand, so we can receive comments and suggestions.

The extension is available at, http://www.yiiframew…wbmodelcommand/

Bug fix version R4202 (Feb. 6 2009),

  • fixed few bug on generation result display
  • incorporated new model template from 1.0.2 with protectedAttributes block removed
  • enhanced ability to detect M:M relationship with composite keys, i.e. the related tables have PK with more than one field

Minor bug fix version R2464 (Feb. 17 2009),

  • fixed few bug on file path with \ backslash for windows platform

I haven't tested the command yet, just reading the forum and your blog.

For MANYMANY relationships, do I get a model class generated for the Table1_has_Table2 or not?

For example, you have Table1 and Table2, and they are in M:M relationship, ie. you have a composite TableC which contains only the primary keys from Table1 and Table2 (other wise 1:M and M:1 will take place). When the classes are generated,

In Table1, it would have something like:

'Table2'=>array(self::MANY_MANY, 'Table1', 'TableC(t1ID, t2ID)')

Similarly in Table2 you get,

'Table1'=>array(self::MANY_MANY, 'Table2', 'TableC(t1ID, t2ID)')

It also generates a class for TableC with,

'Table1'=>array(self::BELONGS_TO, 'Table1', 't1ID'),

'Table2'=>array(self::BELONGS_TO, 'Table2', 't2ID')

Not sure if the class for TableC is useful though.

We've tried this with two of our project, and seems all the relations are generated correctly. Please test against your database model and see if there's anything inappropriate. Look forward to your results.

Didn't try it yet, as it says you need to work with MySQL Workbench. Does it also work with DBDesigner 4?

Sorry Mike I don't think it would work with DBDesigner, since its saved XML file has different schema. However if you wish to try MySQL workbench, which would help you import DBDesigner XML file and then you can save your diagram to mwb file, which should work with our script.

We used to use DBDesigner too, the main reason we jumped to MWB is DBDesigner is out of maintenance for quite a while and still buggy, whereas MWB seems got better community support now, though it's still way off a full featured DB IDE (OSS Edition).

Give a go and let us know if there's any problem with your database model.

Thanks for the update. Let's see if i give MWB another try. Whenever i did, it appeared unusable and too complicated in the end and i switched back to DBDesigner. There's even a fork which seems to have some bugs fixed.

I was going to try it but didn't work after I installed it.

Here is the steps that I took:

  1. Put the mwbModelCommand_R2402 file under 'framewok/cli'

  2. At the yiic shell typed "wmbmodel [mwb-file]" and nothing happend!

Can someone please help me on this issue?

Thanks,

Ramin

Sorry Ramin, it's my bad, I had a typo in the documentation, the command line should be,

>mwbmodel <mwbfile>

mwb stands for MySQL Workbench.

Didn't work! Are you sure it should be under …/framework/cli folder?

User shell commands should be placed under 'protected/commands/shell'

Hi Ramin, as I mentioned in the documentation, we have created this extension for the framework, so please make sure you have,

mwbModelCommand.php is under framework/cli/commands/shell folder

and model_relations.php is under framework/cli/views/shell/model

Please launch yiic at the folder of your project's folder where the dispatcher script (index.php) is.

Should you still have any problem, please post back any error messages or screen dumps.

cheers!

Hi unikly, I decided to test your extension, but I am not being able to make it work.

I've placed all files as instructed and created a simple ONE to MANY relationship between two tables on a file named d:\website.mwb.

After I get into the shell, I run the command and get the following:

simplexml_load_file(): I/O warning : failed to load external entity &quot;zip://

d:%5Cwebsite.wmb#document.mwb.xml&quot;</p>

Which refers to :

$xml = simplexml_load_file("zip://".$file."#document.mwb.xml");

I am using WAMP and therefore have enabled zip and xml support.

What am I doing wrong?

Many thanks for the help and the very handy idea! :)

Cass

Hi unikly, I decided to test your extension, but I am not being able to make it work.

I've placed all files as instructed and created some tables on a file named D:\PHPnow\htdocs\slp_oa_m\oa.mwb.

After I get into the shell, I run the command and get the following:

mwbModel D:PHPnowhtdocsslp_oa_moa.mwb;


PHP Parse error:  syntax error, unexpected T_STRING in D:PHPnowhtdocsframewor


kclicommandsShellCommand.php(102) : eval()'d code on line 1





Parse error: syntax error, unexpected T_STRING in D:PHPnowhtdocsframeworkcli


commandsShellCommand.php(102) : eval()'d code on line 1

I am using mwbModelCommand_R2402.zip and Yii1.02  .

What am I doing wrong?

Many thanks for the help and the very handy idea!

Hi Cass,

What version of MySQL workbench are you using?

Can you try to unzip your oa.mwb file and see if you would get a single file named document.mwb.xml. If that's not the case, could you please advice your MWB version and the xml file name you get after unzip.

Since .mwb are simply zipped xml file, that code line you quoted simply try to open the xml file within the zipped mwb file, that's where it fails.

We've only tested the script again few recent MWB 5.0 OSS releases, which all having the same xml name within it's .mwb file, that's why we made a quick assumption that the script should always read document.mwb.xml. Maybe that's not the case for your mwb file, could you please confirm. Thanks!

cheers

Hi sharehua,

Thanks for your feedback.

From your post, all I can tell is you had the command as 'mwbModel', which should rather in lowercase as 'mwbmodel'. I believe yii shell is case sensitive.

However when we type in a wrong command, it normally returns a empty line instead of the error you got. So, could you confirm if the lower case command would do the trick, thanks!

We might need to ask Qiang to add something like 'Command not found' prompt in the ShellCommand.php and display of a list of available commands if possible.

8)

Hi Unikly,

Thanks for the feedback. I am not at home at the moment so do not know the versions, but it will be the latest community version available on the mysql website (5.0.29).

I am off to London to watch Brasil X Italy tonight, but as soon as I am back, tomorrow evening, I will give it a try and let you know of the outcome. I thank you in advance for your help.

Cass

Quote

Hi Cass,

What version of MySQL workbench are you using?

Can you try to unzip your oa.mwb file and see if you would get a single file named document.mwb.xml. If that's not the case, could you please advice your MWB version and the xml file name you get after unzip.

Since .mwb are simply zipped xml file, that code line you quoted simply try to open the xml file within the zipped mwb file, that's where it fails.

We've only tested the script again few recent MWB 5.0 OSS releases, which all having the same xml name within it's .mwb file, that's why we made a quick assumption that the script should always read document.mwb.xml. Maybe that's not the case for your mwb file, could you please confirm. Thanks!

cheers

Hi unikly.

I get the same problem as the other guys using the mwbmodel command in lowercase. :-\

Hi Unikly,

The previous problem was because of the zip file. But now I am getting the following error. Thanks, Ramin.

>> mdbmodel pm.mwb

Parse error: parse error in C:\yii\framework\cli\commands\ShellCommand.php(102)

: eval()'d code on line 1

Hi Ramin,

Instead of

>> mdbmodel pm.mwb

You need to type in

>> mwbmodel pm.mwb

::)

Thanks Karma. That was a typo when I was replying not issuing the command at the shell and still getting the same error message:

Parse error: parse error in C:\yii\framework\cli\commands\ShellCommand.php(102)

: eval()'d code on line 1

FYI: I am able to unzip my mwb file manually and read its content.