Hey, I have a simple one-to-many relation, between questions and answers. Each question may have 0 or more answers, so any *db.answer.question* refers to a certain *db.question.id*.
Now, in order to create a code for efficiently displaying the questions and their belonging answers, I wonder: how to make the sql query, and how to generate the json object of the question and answer data? My preferred result of the json object would be a list of questions with the answers as a child list. Something like this: *[* * {"text": "Question 1", "owner": 1, "id": 17},* * {"text": "Question 2", "owner": 1, "id": 18, "answers":[{...},{...}] }* *]* I'm thinking of different ways: 1. I can make one left outer join query to get all data in one sql operation, and then perhaps create a subset of questions and answers using the find of db objects. Is this even possible, as I wouldn't know the syntax of the sql query, nor of how to create such a json object. 2. I can make two queries, one for all the questions, one for all the answers, and create a python object in such a way that would generate the correct json object using response.json( python_object ). This solution doesn't seem very fast to code for me, as I don't know if web2py can make this easy for me using built-in tools. 3. I can make two queries, one for all the questions, one for all the answers, and let the javascript do the sorting. I think it would be fastest to let mysql do the sorting, and perhaps it wouldn't be so difficult to do any of the other solutions if you know web2py well enough. I wouldn't like to make my app too javascript heavy. Thanks a lot if you can help me further with this :) -- 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.