如何使用多语言数据库模式与ORM? [英] How to use multilanguage database schema with ORM?

查看:183
本文介绍了如何使用多语言数据库模式与ORM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!

我正在寻找实现多语言数据库模式的最佳方法,我使用的方法与这里相同:多语言数据库设计的最佳实践是什么?(一个具有语言中性的表格数据和一个用于所有翻译)。

I'm searching for the best way to implement multilanguage database schema, the approach I use is the same as here: What are best practices for multi-language database design? (one table with language neutral data and one for all translation). It seems to be good and clean and doesn't limit number of possible languages.

但我想使用一个简单的ORM(如C#中的LINQ,PHP中的Outlet等) )其中每个表都映射到实体类。这可以工作,但查询变得更复杂。

But I want to use a simple ORM (like LINQ in C#, Outlet for PHP etc) where each table is mapped to entity class. This can work, but queries became more complex.

可能有一些特殊的技术来使用这样的DB shema与ORM?或者我可以从支持更复杂映射的更复杂的ORM中受益?

May be there are some special techniques to use such DB shema with ORM? Or I can benefit from more complex ORMs which support more complex mappings?

提前感谢!

推荐答案

对于所有翻译,只使用一个表格可能会导致任何操作的严重性能和复杂性问题(选择/插入/更新/删除);只需尝试理解我的意思。

Using only one table for all translations may quickly lead to severe performance and complexity issues for any operation (select/insert/update/delete) ; just try it to understand what I mean.

然后我会去下面的方法(每个翻译对象两个表),这似乎在性能,复杂性和维护问题。

I would then go for the following method (two tables per "translatable" object), which seems a good balance between performance, complexity, and maintenance issues.

product
  - id (PK)
  - number1
  - number2
  - date1
  - date2
  ...

product_i18n
  - id (PK)
  - product_id (FK)
  - language_id (FK)
  - string1
  - string2
  ...

language
  - id (PK)
  - name

检查如何使用Propel ORM(PHP): http://propelorm.org/blog/2011/01/11 /propel-gets-i18n-behavior-and-why-it-matters.html

Check how it's done with Propel ORM (PHP) : http://propelorm.org/blog/2011/01/11/propel-gets-i18n-behavior-and-why-it-matters.html

HTH

这篇关于如何使用多语言数据库模式与ORM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆