dregvw1801 2011-03-22 20:06
浏览 41
已采纳

PHP ORM继承解决方法?


I'm building a web app and would like to use an ORM to map the data from db with objects.
I have been struggling with this for a few days, and tried various implementations, including: Codeigniter ORM, Kohana ORM, PHP.ActiveRecords and Doctrine.
The last two I can't really use, because they depend on PHP 5.3 which is not installed (and can not be) on my shared hosting server.

The problem with all these ORM-s is inheritance (except for Doctrine, but I can' use it).
I know a lot of developers just do db-s without inheritance, but here is my problem:

My db needs to be multilingual, I designed my db by the following example:
Table Product -> id, category_id, price... (everything that is not translatable)
Table ProductTranslation-> id, language_id, name, description... (same id as product, adds language FK, and fields that are translatable)

Maybe there is a better approach, but I really like this, because its very flexible (can add new languages) and does not put a lot of NULL-s in the db, also joining is not that costly because the tables are relatively small (unlike the approach to put all translations in a single table, and reference that table from all other tables).

The only workaround, I found, to support ORMs is to put a has_one relation between
Product->ProductTranslation.

This way I could access the translated fields with something like:
DB::get_product_by_id(4)->translation->name

Nevermind the syntax, but the real problem with this approach is that I have to define new objects(models) for translation tables, and logically they don't belong there. They are not entities, just additional data for the entities.

So, my question here are:

  • Is there a better way to organize languages in the db, which is more ORM friendly ?
  • Are there any other PHP ORM-s (<5.3) which support inheritance ? - Btw. I found the Kohana ORM ihertiance module but it seems out-of-date, and doesn't work with the current framework version
  • Are there any other workaround for the inheritance problem?
  • 写回答

2条回答 默认 最新

  • dongyong8098 2011-03-22 20:13
    关注

    Doctrine 2.0 requires PHP 5.3, but Doctrine 1.2.x works fine on PHP 5.2.3 or newer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起