开发者

DBIx::Class result classes and actual tables

I'm studying DBIx classes and I'm a bit confused since my interaction with a database so far has been plain SQL queries in PHP code.

Anyway, as I understand it, the class operates with the schema defined in the result classes instead of interacting directly with the database. The schema can be either be built manually via the various .pm classes or pulled from the database via the Loader class.

My question is: what is the preferred approach to this? What if I manually build my result classes and then alter my database? I guess I have to edit both the tables and the classes, isn't it a bit impractical?

T开发者_C百科hanks


One of the difficulties in using an object-relational mapping system like DBIx::Class is that you have to keep your table classes up-to-date with your schema. Usually, it's as simple as adding a field here and there, maybe adding a new foreign key relation once in a while. If you've got your code in version control, then it should be relatively simple to keep track.

The disadvantage of maintaining the same thing (DB schema) in two places is outweighed (IMHO) by the advantage of having an ORM system in place. Once you get used to working with DBIx::Class queries and their ResultSets things go a lot faster than writing raw DBI calls all the time.

Personally, I've not had good luck with the Loader classes, but it's been quite a while since I've tried them. If they work for you, it's probably easier than manually maintaining your schema definitions in the code. On the other hand, I have never been bothered by the minuscule effort that this requires. Database schemas tend not to change too often once a system is up and running.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜