as always without real data is hard to figureout what you want, but I think 
this is....

db(db.model.id == 
db.products.model)(db.model.model.contains(search_term)).select(db.products.ALL)

or, alternatively

models = db(db.model.model.contains(search_term))._select(db.model.id)
db(db.products.model.belongs(models)).select()

On Tuesday, November 19, 2013 3:11:48 PM UTC+1, Richard wrote:
>
> Hmm, this can't work db.product.model.model.contains(search_model)...
>
> It should be this : db.product.model.contains(search_model)
>
> If search_model contain an id, since you reference model...
>
> There is way to use a different FK then the id field of a referenced table 
> if it what you want, you should read the book about that...
>
> I think you can acheive that with IS_IN_DB(db, 'model.model', '%(model)s') 
> instead of Field('model', 'reference model'), you should have :
>
> Field('model', 'string', requires=IS_IN_DB(db, 'model.model', '%(model)s')
> ), 
>
> But more info on what you really want to do could help propose the answer 
> you really want...
>
> Richard
>
>
> On Tue, Nov 19, 2013 at 9:00 AM, 黄祥 <[email protected] 
> <javascript:>>wrote:
>
>> hi, 
>>
>> is it possible to query contains to another table?
>> e.g.
>> db.define_table('model', 
>> Field('model'), 
>> format = '%(model)s')
>>
>> db.define_table('product', 
>>  Field('model', 'reference model'), 
>> Field('serial_number'), 
>> Field('description', 'text'), 
>>  format = lambda r: '%s-%s' % (r.model.model, r.serial_number))
>>
>> search_model = request.vars.search_model
>> rows = db(db.product.model.model.contains(search_model) ).select()
>>
>> i've tried this but it return an error.
>>
>> how can achieve that in web2py way?
>>
>> thanks and best regards,
>> stifan
>>
>> -- 
>> 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] <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

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

Reply via email to