I'm using TurboGears 2.0, SQLAlchemy 0.5.1 and TurboJson 1.2.1 and let
me say first, it is by far the most productive and enjoyable
environment I've ever worked in, and I'm still a novice with it.
Amazing framework, thanks for all your efforts.

I am having a problem dealing with an association proxy. Basically,
jsonify doesn't know how to deal with the collections that the
AssociationProxy is creating, but it doesn't skip them either, it
tries to jsonify the _AssociationProxy_kw_<int> storage key. What's
the correct way to handle this? In my case, I'd like the association
proxy to be returned in the json, but I could understand if the
correct default would be to simply skip _AssociationProxy_ keys, the
same way the _sa_ keys are treated. I can certainly add a jsonify.when
decorator and just do a copy on the collection (ie _AssociationList),
but it would still be under an unknowable key since the int on the end
is different every time. Overriding __json__ for any class that
happens to have an association proxy seems like overkill, but it's
fairly easy if that's what's required.

Thanks in advance.

Here's the applicable section of my model, pretty standard stuff, I
think:

class List(DeclarativeBase):
    id = Column(Integer, primary_key=True)
    kw = relation(Keyword, secondary=list_keyword_table,
backref='lists', lazy=False)
    keywords = association_proxy('kw', 'display_name',
creator=_create_keyword)
class Keyword(DeclarativeBase):
    id = Column(Integer, primary_key=True)
    display_name = Column(Unicode(255), nullable=False, unique=True)

And my controller:

    @without_trailing_slash
    @expose('json')
    def get_one(self, id_or_name):
        l = List.by_id_or_name(id_or_name)
        if (not request.accept.accept_html()):
            for k in l.keywords:
                pass
            return {'list': l}

--~--~---------~--~----~------------~-------~--~----~
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