the important part is that you cache it somewhere, either using 
select(..cache) or storing the actual set to pass to the is_in_set 
validator.

On Thursday, August 1, 2013 2:56:40 PM UTC+2, Antonis Konstantinos Tzorvas 
wrote:
>
> i don't know much about cache yet,
> if i am not mistaken it caches the two queries separated
>
> my query is this: years = [i.year for i in union(db(db.table1.station_id==
> this_station.id).select(db.table1.year),db(db.table2.station_id==
> this_station.id).select(db.table2.year)).sort(lambda row: row.year)]
>
> maybe i can create a function which will return the list of available 
> records for the IS_IN_SET validator,  
> the function will be something like:
>
> def yearset(id):
>   return [i.year for i in 
> union(db(db.table1.station_id==id).select(db.table1.year),db(db.table2.station_id==id).select(db.table2.year)).sort(lambda
>  
> row: row.year)]
>
> so i can cache this with something like this (?)
> cache.ram(str(id), lambda: yearset(id), seconds) 
>
> i have to read more about this so i can fully understand how it works
>
> On Thursday, August 1, 2013 3:27:43 PM UTC+3, Niphlod wrote:
>>
>> I sincerely hope that this gets cached somewhere in your app, because if 
>> instead they are in models, you're doing 2 selects for every request 
>>
>> On Thursday, August 1, 2013 2:21:07 PM UTC+2, Antonis Konstantinos 
>> Tzorvas wrote:
>>>
>>> yes you are right, i was looking also in IS_IN_SET
>>> and finally after your reminder one solution came up easily,
>>>
>>> IS_IN_SET([i.name for i in rows = union(db().select(db.a.name
>>> ),db().select(db.b.name)).sort(lambda row: row.name)])
>>>
>>> which now displays all the values of a required column from both tables!
>>> don't know if there is a better way to do this, or a way to use 
>>> IS_IN_DB() but i think that this one works
>>>
>>> On Thursday, August 1, 2013 2:48:40 PM UTC+3, viniciusban wrote:
>>>>
>>>> I don't think so. 
>>>>
>>>> The book says IS_IN_DB() can receive a Set, but not Rows. 
>>>>
>>>> On Thu, Aug 1, 2013 at 8:33 AM, Antonis Konstantinos Tzorvas 
>>>> <[email protected]> wrote: 
>>>> >> --- https://groups.google.com/d/msg/web2py/o3GebSeC7j4/Sct76ynB3fsJ---- 
>>>> >> 
>>>> >> db=DAL()db.define_table('a',Field('name')) 
>>>> >> db.define_table('b',Field('name')) 
>>>> >> db.a.insert(name='Alex') 
>>>> >> db.a.insert(name='Max') 
>>>> >> db.a.insert(name='Tim') 
>>>> >> db.b.insert(name='John') 
>>>> >> db.b.insert(name='Jack') 
>>>> >> def union(x,y): 
>>>> >>     y.colnames=x.colnames 
>>>> >>     return x|y 
>>>> >> 
>>>> >> rows = union(db().select(db.a.name),db().select(db.b.name)).sort(lambda 
>>>>
>>>> >> row: row.name) 
>>>> >> 
>>>> >> for row in rows: print row.name 
>>>> > 
>>>> > 
>>>> > this one worked for the union select part, 
>>>> > but how can i use it with a validator like IS_IN_DB for a form? 
>>>> > 
>>>> > i have two identical tables which data are from different source but 
>>>> the 
>>>> > structure is the same 
>>>> > 
>>>> > -- 
>>>> > 
>>>> > --- 
>>>> > 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/groups/opt_out. 
>>>> > 
>>>> > 
>>>>
>>>

-- 

--- 
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/groups/opt_out.


Reply via email to