Hey Alex, 

Thanks for the suggestion. The problem with the query is that 
'location_one.geom.st_equals(point_x_y)' won't work. That's because the 
table db.item_location doesn't have a field called 'geom'. This is the 
error:

AttributeError: 'Table' object has no attribute 'geom'


Is there a way to implicitly reference the fields in another table so that 
it will work?

On Tuesday, August 27, 2013 3:15:10 PM UTC-4, Alex wrote:
>
> try something like this:
>
>
> location_one = db.item_location.with_alias('location_one')
> location_two = db.item_location.with_alias('location_two')
> rows = db((db.item_location.item == db.item.id) & (db.item.id != itemid) & 
> (db.item_location.location_one == location_one.id) & 
> (db.item_location.location_two 
> == location_two.id) &
>      (location_one.geom.st_equals(point_x_y)) & (location_two.geom.
> st_equals(point_n_m))).select(db.item.ALL)
>
> Alex
>
> Am Dienstag, 27. August 2013 19:43:08 UTC+2 schrieb Apple Mason:
>>
>> I have this many to many relationship example:
>>
>> db.define_table('location',
>>     Field('geom', 'geometry()'))
>>
>> db.define_table('item',
>>     Field('name'))
>>
>> db.define_table('item_location',
>>     Field('item', db.item),
>>     Field('location_one', db.location),
>>     Field('location_two', db.location))
>>
>>
>>
>> The goal is to find all items that are NOT the given item.id, but 
>> matches locations.
>>  An example query would be:
>>
>> Given: item.id==1 and two points POINT(x,y) and POINT(n,m), 
>> Result: "get all items that are not item.id==1, but has 
>> location_one==POINT(x,y) and location_two==POINT(n,m)"
>>
>> I am able to get it matching one of the points, but not the other with 
>> this:
>>
>>
>> point_x_y = "POINT(1,2)"
>> point_n_m = "POINT(3,4)"
>> itemid = 1
>>
>> t = db( (db.item.id==db.item_location.item) &  
>>            ( (db.location.id==db.item_location.location_one) & (db.
>> location.geom.st_equals(point_x_y))))
>>
>> result = t( db.item.id != itemid ).select()
>>
>>
>> This will successfully match all items that do not have an id=1, and has 
>> location_one as point_x_y.
>>
>> The problem is I do not know how to match location_two with point_n_m. I 
>> tried this, but it doesn't make sense (it also returns in nothing):
>>
>> t = db( (db.item.id==db.item_location.item) &  
>>            ( (db.location.id==db.item_location.location_one) & (db.
>> location.geom.st_equals(point_x_y)))
>>            ( (db.location.id==db.item_location.location_two) & (db.
>> location.geom.st_equals(point_n_m))))
>>
>> Any help would be great!
>>
>

-- 

--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to