我已经用了几种不同的方法。我想知道这是否有一个好的模式。
系统具有动态内容。因此,不仅数据量和数据本身是动态的(count(rows)),而且字段的数量也是动态的。因此,一个博客可能有10个字段需要翻译,但购物车项目有5个。
我一直在做的是为保存该字段的语言数据的表行插入一个id。此语言表具有id、defaultlanguage和任意数量的其他语言。这样就只有一个语言表。
这很漂亮,但是我不能更新视图,因为当多个连接引用同一个表时,它是不可更新的(mysql)。那么也许有更好的方法来做这件事。
有更好的设计吗?在这种情况下,常用的设计模式有哪些?

最佳答案

实体字段类型(ID、名称)
实体字段(ID、名称、字段类型)
实体字段值(id,collectionid,field,value)
实体内容(id、字段、数据)
实体I18N(ID、字段、语言ID、值)
例子:

insert into FieldTypes('S', 'string');
insert into FieldTypes('DT', 'date/time');

insert into Fields(1, 'Author', 'S');
insert into Fields(2, 'Created', 'D');

insert into i18n(1, 1, 'en', 'Author');
insert into i18n(2, 1, 'ru', 'Автор');
insert into i18n(3, 2, 'en', 'Created');
insert into i18n(4, 2, 'ru', 'Создано');

insert into Content(1, 2, 'Test data');
insert into FieldValues(3, 2, 1, 'Tester');
insert into FieldValues(4, 2, 2, '2011-03-20T12:20:00');

/* Display content fields in the user language */
select c.ID, f.ID, i.Value as FieldName, fv.Value as FieldValue
from Content c, FieldValues fv, Fields f, i18n i
where c.Fields = fv.CollectionID
  and fv.Field = i.Field
  and i.LanguageID = :UserLanguage
  and c.ID = :ContentID

10-04 15:51
查看更多