开发者

best way to create tables with ORM?

assume that i start coding an application from scratch, is the best way to create tables when using an ORM (doctrine), to manually create tables in mysql and then generate models from the tables, or is it the other way around, that is to create the models in php and then generate tables from models?

and if i already have a database, will the models created be o开发者_如何转开发ptimal? cause i have heard some say that its best to create the database from scratch when using ORM, so that the relations are optimized for OOD.

share your thoughts!


I think that ORM promotes an OO approach i.e. to start with the object model and to generate the tables from it. And this is usually what I do when starting from scratch. But once the database goes live, I don't generate things anymore, I use changes scripts. This applies also if you need to tune the database (with indices, denormalized columns) and can't handle that with your ORM.

But some prefer the other way around, especially DBAs, and there is nothing really bad with this unless the model is heavily denormalized in which case it may not map to a nice OO model. In such cases, you may get better results with a data mapper than with an ORM.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜