开发者

Having a relation 1 to many on Doctrine but having 2 fields being the primary key on the other end

开发者 https://www.devze.com 2022-12-18 11:20 出处:网络
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

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_fi开发者_开发技巧eld2 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 :)


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消