在 Doctrine 上有 1 对多的关系,但在另一端有 2 个字段作为主键
有谁知道我如何在学说上建立1对多的关系,但以这种特殊的方式:
在我的主表中,我有一些字段,但它们都不是可以进行翻译的字段,
Table1:
table_id <- primary key
numeric_field1
numeric_field1
numeric_field3
现在在我的Table1_translations中,我拥有可以进行翻译的所有字段 我对
Table2:
table_id <- primary key along with language
language <- this contains 2 letters representing which language is being stored in this row
string_field1
string_field2
string_field3
如何用 YAML 表示这个有一个简单的想法,但我的问题是,如何检索这些数据?
Table1:
table_id numeric_field1 numeric_field2 numeric_field3
1 123 321 415
Table2
table_id language string_field1 string_field2 string_field3
1 en hello happy world
1 es hola feliz mundo
因此,对于 table_id=1 的行,我在 table2 中有 2 行,分别对应于不同语言(en 和 es)的字符串,我试图管理某种本地化,但在数据库上,因为这些可能是文本,
谢谢提前:)
Does anyone knows how can I have a relation 1 to many in doctrine but in this special way:
in my principal table I have some fields, almnost none of them are fields which could have translations
Table1:
table_id <- primary key
numeric_field1
numeric_field1
numeric_field3
now in my Table1_translations I have all the fields which could be translated
Table2:
table_id <- primary key along with language
language <- this contains 2 letters representing which language is being stored in this row
string_field1
string_field2
string_field3
I've got a simple idea on how to represent this with YAML, but my question would be, how can I retrieve this data?
Table1:
table_id numeric_field1 numeric_field2 numeric_field3
1 123 321 415
Table2
table_id language string_field1 string_field2 string_field3
1 en hello happy world
1 es hola feliz mundo
So, for row with table_id=1 I have 2 rows in table2 which correspond to the strings each in a different language (en & es) with this im trying to manage some sort of localization but on the database since these could be texts
thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您只需要添加一个 where 子句,根据本地化指定您想要哪种语言。因此,如果您在应用程序或数据库中为用户存储语言变量,那么您只需添加一个引用该变量的 where 子句或连接到用户表即可获取该人需要的本地语言(尽管我建议抓住该值在登录时一次并在整个会话中保持可用)。
I think all you need to add a where clause specifying which language you want based on localization. So if you, in the application or the database, store a language variable for the user, then you simply add a where clause refernceing this variable or joining to the user table to get the local language that person needs (altough I'd suggest grabbing this value once on login and keeping it avialble thorugh the whole session).