[Catalyst] Adding relationships to loaded CDBI models

Danijel Milicevic Danijel.Milicevic at rawmode.org
Thu Jun 16 20:33:40 CEST 2005


Hi Rob,

Am Donnerstag, den 16.06.2005, 13:52 -0400 schrieb Rob Kinyon:
> > All you have to do is supply a dbi path to the myapp_create.pl helper
> > script, it'll create classes for your tables. An example:
> > 
> > gabb at spalato:~/MyApp$ sqlite3 /tmp/myapp.db < myapp.sql
> > gabb at spalato:~/MyApp$ script/myapp_create.pl model CDBI CDBI dbi:SQLite:/tmp/myapp.db
> > created "/home/gabbana/MyApp/script/../lib/MyApp/M/CDBI.pm"
> > created "/home/gabbana/MyApp/script/../lib/MyApp/M/CDBI"
> > created "/home/gabbana/MyApp/script/../lib/MyApp/M/CDBI/Item.pm"
> > 
> > Then you add the relationships in MyApp::M::CDBI::Item, and _NOT_ in CDBI.pm.
> > Re-running the helper script won't overwrite existing modules btw, so you can run it everytime you update your SQL.
> 
> This brings up an interesting point - what if you're not using SQLite,
> but instead are using MySQL/Oracle/Sybase/etc. Some of those dbi:
> strings can get quite long. What's a best practice for handling that?

I'm not too sure if I can call it best practice already, but most of us
(the guys in #catalyst) do supply those "quite long" strings nonetheless
to the helper method and export the configuration laters to a YAML file.
Quite useful if you use a simple and lightweight DB like SQLite during
development and move laters to MySQL/Oracle/PostgreSQL in production.

A good example on this can be found in trunk/examples/ServerDB.

Regards,
Danijel




More information about the Catalyst mailing list