Hi,
I have a database where following structure is quite common:
db.define_table('thing',
Field('name)
)
db.define_table('property',
Field('name)
)
db.define_table('thing_has_property',
Field('thing_id', 'reference thing'),
Field('property_id', 'reference property'),
Field('order_number', 'integer', default=1, notnull=True)
)Order number is not always present, but in many cases it's necessary. Basically it tells the order of properties for the given thing.
I want to get listing of all things and their properties. I can do the following:query = (db.thing.id == db.thing_has_property.thing_id) &
(db.thing_has_property.property_id == db.property.id) things_and_their_properties = db(query).select()
However, I would like to get the data in a format where I have each thing listed only once and all it's properties are in the same row in right order based on the order number. Like
things_and_their_properties = [
['thing1', 'p1', 'p2', 'p7'],
['thing2', 'p1', 'p4'],
etc...
]
Currently I'm doing this kind of restructuring manually and sometimes it's quite complicated since some of those datastructures are way more complex than this. I'm wondering, is there any way to do this kind of sorting with web2py? So that I could get rows which are already in format I need in my application. I think that my need is quite common so I guess there is some kind of standard way to do this.
Thanks in advance!