In your query, are you doing a join with the photos table to actually 
retrieve the photos? If so, only the records with photos will be returned 
(assuming an inner join). Otherwise, you can do a nested select 
<http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#belongs>
:

vehicles_with_photos = db(db.photos.Vehicle != None)._select(db.photos.
Vehicle, distinct=True)
query &= db.vehicles.id.belongs(vehicles_with_photos)

Anthony 

On Monday, November 28, 2016 at 7:06:34 AM UTC-5, Áureo Dias Neto wrote:
>
> I have a table, called 'vehicles', and this has so many fields. In 
> another, table, called 'photos', I have a field, called 'Vehicle', which is 
> reference to my vehicle table ..
>
> I'm doing a search form, and I need to filter records from my vehicle 
> table, which have been referenced in the 'photos' table.
>
> Example, I'm using a query: innitial, the query starts 'query = 
> db.veiculos.id> 0' ..
>
> And accordingly, the user fills the search form, I filter this query. For 
> example: query & = db.veiculos.name == form.vars.name,
>
> In this search form, I have a field that is 'fotos: yes / no' ..
> If the user select 'yes', I want to go to my photos table, check which 
> vehicles in the vehicles table, were referenced in any record in the photos 
> table, ie, which vehicles have photos .. and filter this query in the same 
> idea .. .
>
> Thanks a lot
>

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