I'm having a problem understanding how to serve my data best. I have 2 models, one is record and the other is log, they have a 1 to many relationship respectively. I'd like to serve this using tg's RestController so I can do mysite.com/api/record_id/log So far I have this:
class API(RestController):
@expose('json')
def get_all(self):
records = DB.query(Record).all()
return dict(records=records)
@expose('json')
def get_one(self, record_id):
try:
record = DB.query(Record).filter(
Record.record_id==record_id).one()
except NoResultFound:
abort(404)
return dict(record=record)
@expose('json')
def log(self, record_id):
try:
log = DB.query(Log).filter(
Log.record_id==record_id).all()
except NoResultFound:
abort(404)
return dict(log=log)
This works, however, if I go to mysite.com/api/log then it maps (as expected) to the log method and complains about the missing variable record_id. How can this be done so the log method is only accessible after the record resource?