jfinkels/flask-restless — pull request #161 by bjourne (2013-03-12 08:59:12+00:00)
Title: API to control how relationships are serialized

Currently flask-restless follows all relationships downwards and upwards when serializing models to json. It can be pretty bad for performance because it can result in hundreds of queries to return a single object. My proposed "simple" solution is to only serialize already loaded relationships, but skip those that require database lookups. E.g:

class User(db.Model):
scores = db.relationship('Score', lazy = 'dynamic')

This would not fetch all scores because `lazy='dynamic'` means the relatoinship isn't loaded.

class User(db.Model):
scores = db.relationship('Score', lazy = 'joined')

But this would because `joined` means sqlalchemy preloads the score rows.

A real API for controlling traversal would be nice, but some control is better than nothing. :) Please ignore all commits in the pr expect for (https://github.com/bjourne/flask-restless/commit/6bebdd7e785c3ae6f4aa22ce00e57354e715860e), i wasn't able to isolate it cleanly.