I'm posting this question here as well as on
stackoverflow<http://stackoverflow.com/questions/11991678/can-web2py-serve-rest-data-of-many-to-may-tables-via-parse-as-rest>.
So hopefully the extra exposure will help me out!
I need to serve REST data about a many-to-many relationship. I've been
playing with web2py's lovely parse_as_rest functionality, but can't quite
get the many-to-many thing working.
As an example, let's take standard users and groups.
Tables:
- user
- id
- user_name
- group
- id
- group_name
- membership
- id
- user_id
- group_id
What pattern do I need to use to serve a url that will give me all
group_name's that a user belongs to?
patterns = [
"/user[user]",
"/user[user]/id/{user.id}",
"/user[user]/id/{user.id}/membership[membership.user_id]",
# This is the line that I can't make yet:
#"/user[user]/id/{user.id}/membership[membership.user_id]/group<WHAT
GOES HERE>",
"/group[group]",
"/group[group]/id/{group.id}",
]
parser = db.parse_as_rest(patterns, args, vars)
With the non-commented lines above, I can get to these urls:
1. .../user
2. .../user/id/1
3. .../user/id/1/membership
4. .../group
5. .../group/id/3
URL #3 shows me all my memberships, and I can then make several separate
calls to URL #5 to get the group_name values, but there's got to be a way
to do this with one call.
Help me web2py google forum! You're my only hope. (Besides
stackoverflow<http://stackoverflow.com/questions/11991678/can-web2py-serve-rest-data-of-many-to-may-tables-via-parse-as-rest>
of
course!)
--