For a project I just started I am wanting to expose json data using a
restful api for mobile and desktop clients to download information for
offline use. The parse_as_rest has been a great resource for doing this.
I have used the patterns to expose various tables. This has worked great
when looking at singular tables or 2 tables when it is a one to many
relationship. However I am stumped about how I can use patterns to allow
getting records that span across many to many relationships, or when
linking more than 2 tables. Lets say the data model looks like this:
db.define_table('person',
Field('name'),
Field('info'))
db.define_table('pet',
Field('name'),
Field('info'))
db.define_table('ownership',
Field('personid','reference person'),
Field('petid','reference pet'))
db.define_table('toy',
Field('owner',db.pet),
Field('name'),Field('info'))
For the sake of this example I am saying that a person can have multiple
pets, and a pet can be owned by multiple people, a many to many
relationship. Pets also have their toys, though they are not shared, a one
to many relationship.
Using patterns it is easy for me to see how I can do something like list
all the toys owned by a particular pet with a pattern like this:
patterns = ['/pet/{pet.id}/toys[toy.owner]']
However I need to be able to perform a call that allows me to pass in the
person's id and provides the info for all the pets owned by that person.
Also taking it a step further I want to be able to provide a list of toy
names for all the toys owned by pets owned by a particular person again by
making one call in that passes the id of the person.
Can someone provide insight about how I could accomplish this using the
parse_as_rest method and patterns? Or do I need to instead just make a
separate method altogether for these unique cases? I am hoping that
parse_as_rest can be used so I could take advantage of the built in logic
for patterns, complex queries, limits etc.
Any help is greatly appreciated
--