在 Doctrine 上有 1 对多的关系,但在另一端有 2 个字段作为主键

发布于 2024-08-19 18:39:20 字数 925 浏览 2 评论 0原文

有谁知道我如何在学说上建立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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿咻 2024-08-26 18:39:20

我认为您只需要添加一个 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文