piston should not follow foreign keys

8 views
Skip to first unread message

Benedikt Böhm

unread,
Dec 19, 2009, 7:31:09 AM12/19/09
to django...@googlegroups.com
Hi!

i've started to build a backend for a sproutcore app with piston, but
it is really annoying that piston follows foreign keys. for mildly
complex data strcutures this results in WAY too much data being
returned. also sproutcore will handle all relations internally and
expects the backend to return resource ids instead of the already
expanded resource

i haven't found a way to disable this feature, except for some monkey
patching. maybe a configuration option should be added?

Thanks,
Bene

jespern

unread,
Dec 19, 2009, 10:48:19 AM12/19/09
to django-piston
I'd say that following foreign keys is a definite feature. Most of the
time, you don't want to hit the server with more requests than
necessary.

What you *can* do, is override the fields, with what's called
"resource methods." This allows you to override what comes out of that
resource.

For example:

class FooHandler(BaseHandler):
model = Foo
fields = ('id', 'something_fk', ...)

@classmethod
def something_fk(cls, sfk):
return sfk.id

Say 'something_fk' is a foreign key on Foo, now it will pipe that
object through to the 'something_fk' method and return what comes out
of there instead.


HTH,

Jesper

Reply all
Reply to author
Forward
0 new messages