that query is largely inefficient though. use response.toolbar() to see how 
many queries that statement generates.

I really don't get how the data is stored into the model. example records 
of each table and of the resultset would be beneficial to craft the needed 
query

On Friday, April 22, 2016 at 9:36:56 PM UTC+2, Marko Seppälä wrote:
>
> I think that that reference in language_tr table is needed. Otherwise 
> there is no way to translate those for more than one language I think.
>
> For example, if we have two languages, let's say English and German, and 
> we want to translate both languages to both languages. So for example 
> language with code "en" would be translated to "English" with 
> translation.language_id.code == "en" and to "Englisch" 
> with translation.language_id.code == "de". But language_tr would be 
> referencing to language_id.code == "en" in both cases.
>
> Otherwise your answer is very good! I'm still very beginner with this so 
> step by step instructions are very welcome :)
>
> I was able to make it work this way:
> languages = db((db.language_tr.id>0)).select()
> for language in languages.exclude(lambda language: 
> language.translation_id.language_id!=system_language_id):
>     pass
>
> This looks somewhat ugly, I'm sure that there is a better way.
>
> perjantai 22. huhtikuuta 2016 22.02.40 UTC+3 Niphlod kirjoitti:
>>
>> 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.

Reply via email to