duanmu6231 2011-05-02 14:11
浏览 87
已采纳

用学说2映射

I have questions which are represented like this in my SQL database :

CREATE TABLE IF NOT EXISTS `t_question` (
  `id_question` int(10) NOT NULL AUTO_INCREMENT,
  `heading_key` varchar(255) NOT NULL,
  PRIMARY KEY (`id_question`)
) ENGINE=InnoDB;

Because I want my questions to be multilanguage, I link their keys to another table (t_lang_data) which stores strings for several uses (questions, articles and so on).

My t_lang_data has the folowing structure :

CREATE TABLE IF NOT EXISTS `t_lang_data` (
  `id_lang_data` int(10) NOT NULL AUTO_INCREMENT,
  `key` varchar(255) NOT NULL,
  `lang_iso` int(10) NOT NULL,
  `text` varchar(255) NOT NULL,
  PRIMARY KEY (`id_lang_data`)
) ENGINE=InnoDB;

So for example I could have this question :

id_question = 1 ; heading_key = heading_quest_1

And these lang_data entries :

id_lang_data = 1 ; key = heading_quest_1 ; lang_iso = en_UK ; text = "Heading for question 1" id_lang_data = 2 ; key = heading_quest_1 ; lang_iso = fr ; text = "Titre de la question 1"

I need to map these relations for Doctrine 2 but I do not know what to do. I have tried a many-to-one and a one-to-many approch but it does not work.

Do someone has an idea please ? Thanks

EDIT : I realize that it is even more difficult than what I thought. Indeed, my t_lang_data table can store strings for many tables such as t_questions, t_articles and so on. But in the mapping it seems that we can map only two tables together.

So how could I do ?

  • 写回答

1条回答 默认 最新

  • duanqin7791 2011-05-02 14:31
    关注

    You indeed have one of the most common translation issue with databases.

    If you want to have an efficient translation behavior without reinventing the wheel, you should use this library : https://github.com/l3pp4rd/DoctrineExtensions.

    It has been recommended by the doctrine2 team and work perfectly well for me. The documentation dedicated to the translation behavior is here : https://github.com/l3pp4rd/DoctrineExtensions.

    Also if you are using symfony2, the dedicated bundle is here : http:// github.com/stof/DoctrineExtensionsBundle

    Moreover the translation behavior works just like your, by using a table dedicated to translated string storage referencing the original type and id.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?