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:
TableProduct -> 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 a开发者_运维知识库re 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?
Doctrine 2.0 requires PHP 5.3, but Doctrine 1.2.x works fine on PHP 5.2.3 or newer.
why not use Propel's i18n behavior ?
精彩评论