That sounds reasonable.

But, for your facebook example,  there is another problem.  If we
don't want to get these 4000 thousand friends,
we have 2 choices:

1. don't use relationship of SA to use the default encode mechanism of
turbojson
2. write a customized "__json__"

I think, the 1st choice is not acceptable in most cases, but the 2nd
one is also annoying when we have more than 40 tables.

So, how about this :

    Find a way to mark fields of an object that should be skimmed when
encode it to JSON.

On 7月24日, 下午5时34分, "Diez B. Roggisch" <[email protected]> wrote:
> 一首诗 schrieb:
>
>
>
>
>
> > I'm very glad to know that turbojson could automatic convert
> > SQLAlchemy object to JSON.  But unfortunately, it can not handle SA
> > object circuit.
>
> > For example, there are 2 of SA mapped class, User and Role.  User has
> > more than 1 role and a role could be given to many user.   This is a
> > very common M:N relationship in relational database.
>
> > But turbojson can not convert an instance of User to JSON
> > automatically, because there is a reference loop.  What now we can do
> > is add a "__json__" method to manually convert an object json, which
> > is very tedious.
>
> > So my suggestion is : why not just skipped there objects referenced
> > more than one time?  This will be a behavior easily undertood and will
> > save a lot of time writing "__json__".
>
> There are two big problems with this:
>
>   - JSON has no concept of refernces, it's a purely algrebraic
> structure. As a consequence, you can't serialize graph-structures with
> it. So you need to come up with a special key/value pair that denotes a
> reference. This is purely to your own design.
>
>   - if that behavior would be default, it would mean that e.g. returning
> a user in facebook would return all his 4000 friends. Which is a rather
> dumb thing to do if all you want is a user's primary attributes, don't
> you agree?
>
> So I'm afraid this can't be implemented the way you wish. I'm not sure
> how this is dealt with in TG2, but in TG1 it was very easy to declare a
> special rendering for specific objects, based on rules dispatch. You
> should try & do that.
>
> Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to