imho there's a reference not needed (the language_id in the language_tr
table)
that being said...let's build queries, step by step
"""
Basically I'm looking for a list of language_tr elements which has a
translation_id which has a language_id which is same than users selected
system language.
"""
start backwards:
. let's name tables with a shorter name (we don't want to die in the
process of typing)
lng = db.language
trs = db.translation
ltr = db.language_tr
. what's the Query we need to filter out of the language the user selects ?
lng.code == 'user_selected_language'
. what's the translation row(s) related to that record ?
.. we need to join by the link between lng and trs
(lng.id == trs.language_id)
. what are language_tr row(s) related to the trs record ?
.. we need to join by the link between trs and ltr
(trs.id == ltr.translation_id)
. summing up all relations, we now have
(lng.id == trs.language_id) & (trs.id == ltr.translation_id)
. we append our Query
(lng.id == trs.language_id) & (trs.id == ltr.translation_id) & (lng.code
== 'user_selected_language')
. what do we want ? ltr.ALL, let's select it
. cook it up alltogether
db(
(lng.id == trs.language_id) & (trs.id == ltr.translation_id) &
(lng.code == 'user_selected_language')
).select(ltr.ALL)
On Friday, April 22, 2016 at 3:51:51 PM UTC+2, Marko Seppälä wrote:
>
> Hi,
>
> I have a following database:
>
> db.define_table('language',
> Field('code', 'string', unique=True)
> )
>
> db.define_table('translation',
> Field('language_id', 'reference language', notnull=True,
> readable=True, writable=True),
> auth.signature
> )
>
> db.define_table('language_tr',
> Field('translation_id', 'reference translation', notnull=True,
> readable=True, writable=True),
> Field('language_id', 'reference language', notnull=True,
> readable=True, writable=True),
> Field('name', notnull=True)
> )
>
> So basically I have a list of supported languages in the language table.
> Then language_tr table has all names for those languages, in every
> possible language. language_id references to the language which is
> translated and translation_id references to the translation, which has
> language_id
> for the language which is used for the translation.
>
> In database this works great, but I'm having problems to build a simple
> enough database query to get all translations whit selected language only.
> For example, user wants to use English and sets that to system language. So
> I want to show translations only in English, not with all possible
> languages.
>
> What is the most efficient way to get only translations in English?
> Basically I'm looking for a list of language_tr elements which has a
> translation_id
> which has a language_id which is same than users selected system language.
>
> - Marko
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.