Is there a way to get all the information returned as one row, with the 
focus on a particular person? For example, 

<Row {'pet': [{''name': 'Pet1'}, {''name':'Pet2'}], 'person': {'name': 
'Bob', 'id': 1L}, 'thing': [{'name': 'thing1'}, {'name':'thing2'}]}>

... Or something similar? This would give me a single row that I can 
iterate through his things or pets if I need to. For example, to print out 
people's information:

    for person in persons:
          things = .....
          pets = .......

          print "%s %s" % (things, pets)



Right now the code I have is:

        a = db( db.person.id==1).select(db.person.ALL, db.pet.ALL, db.thing.
ALL,
        left=[db.pet.on(db.person.id==db.pet.person_id),
              db.thing.on(db.person.id==db.thing.person_id)])


When I print this out, I get a combination of the same thing, which is a 
mess:


<Row {'pet': {'person_id': 1L, 'id': 1L, 'name': 'Pet1'}, 'person': {'name': 
'Bob', 'id': 1L}, 'thing': {'person_id': 1L, 'id': 1L, 'name': 'thing1'}}>
<Row {'pet': {'person_id': 1L, 'id': 1L, 'name': 'Pet1'}, 'person': {'name': 
'Bob', 'id': 1L}, 'thing': {'person_id': 1L, 'id': 2L, 'name': 'thing2'}}>
<Row {'pet': {'person_id': 1L, 'id': 2L, 'name': 'Pet2'}, 'person': {'name': 
'Bob', 'id': 1L}, 'thing': {'person_id': 1L, 'id': 1L, 'name': 'thing1'}}>
<Row {'pet': {'person_id': 1L, 'id': 2L, 'name': 'Pet2'}, 'person': {'name': 
'Bob', 'id': 1L}, 'thing': {'person_id': 1L, 'id': 2L, 'name': 'thing2'}}>
<Row {'pet': {'person_id': 1L, 'id': 3L, 'name': 'pet3'}, 'person': {'name': 
'Bob', 'id': 1L}, 'thing': {'person_id': 1L, 'id': 1L, 'name': 'thing1'}}>
<Row {'pet': {'person_id': 1L, 'id': 3L, 'name': 'pet3'}, 'person': {'name': 
'Bob', 'id': 1L}, 'thing': {'person_id': 1L, 'id': 2L, 'name': 'thing2'}}>






On Wednesday, January 22, 2014 4:40:31 PM UTC-5, Niphlod wrote:
>
> I'm guessing you had it wrong....
>
> db(main_table.filter == something).select(
>     main_table, other_table, 
>     left=[other_table.on(main_table.some_id == other_table.reference), 
> ....
>     ]
> )
>
>
>
> On Wednesday, January 22, 2014 10:24:14 PM UTC+1, Apple Mason wrote:
>>
>>
>> I have the following tables:
>>
>>
>> db.define_table('person',
>>     Field('name', 'string'))
>>
>> db.define_table('pet',
>>     Field('name', 'string'),
>>     Field('person_id', 'reference person'))
>>
>> db.define_table('thing',
>>     Field('name', 'string'),
>>     Field('person_id', 'reference person'))
>>
>> I have a person_id given to me, so I want all information about that 
>> person (person's name, all pets, all things).
>>
>> I am trying left join, but I am not getting it quite right:
>>
>>  person = db(db.person.id==person_id).select(db.person.ALL, db.pet.ALL, 
>> db.thing.ALL, 
>>                                                                      
>> left=[db.person.on(db.person.id==db.pet.person_id),
>>                                                                              
>> db.person.on(db.person.id==db.thing.person_id)])
>>
>> I get an error:
>>
>> OperationalError: ambiguous column name: person.id
>>
>

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

Reply via email to