【问题标题】:Having a relation 1 to many on Doctrine but having 2 fields being the primary key on the other end在 Doctrine 上具有 1 对多的关系,但在另一端有 2 个字段作为主键
【发布时间】:2010-01-31 20:06:10
【问题描述】:

有谁知道我怎样才能在教义上以这种特殊的方式建立 1 与 many 的关系:

在我的主表中,我有一些字段,但几乎没有一个是可以翻译的字段

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) 的字符串,我试图管理某种本地化但在数据库上,因为这些可能是文字

提前致谢:)

【问题讨论】:

  • 请详细点,数字字段1和字符串row1之间有对应关系吗?为什么称它为“行”1?也许是示例数据?
  • 我也很困惑。您能说明您要做什么(可能有一张带翻译的表格吗?),那么您是如何尝试的,但不要将两者交织在一起。
  • 您的描述与标题有何关联?您现在如何代表它,如何让我们知道您如何代表,以便我们可以帮助您?
  • 抱歉调用 em 行,它们确实是字段。我已将示例数据添加到原始帖子中

标签: php doctrine yaml dql


【解决方案1】:

我认为您只需要添加一个 where 子句,根据本地化指定您想要的语言。因此,如果您在应用程序或数据库中为用户存储一个语言变量,那么您只需添加一个引用该变量的 where 子句或加入用户表以获取该人需要的本地语言(尽管我建议抓取此值在登录时一次,并在整个会话期间保持可用)。

【讨论】:

    猜你喜欢
    • 2020-05-04
    • 2021-10-24
    • 2011-03-31
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    • 2013-01-21
    • 2019-08-17
    • 1970-01-01
    相关资源
    最近更新 更多