I am trying find a nice automatic way to serialize my sql alchemy result
sets when doing joins.
Lets say i have the following 2 models, User and Message:
class User(Base):
__tablename__ = '...'
id = Column(...)
name = Column(...)
last_login Column(...)
and
class Message(Base):
__tablename__ = ...
id = Column(...)
subject = Column(...)
body = Column(...)
date = Column(...)
creator_id = Column(...)
Now, if I do a query like:
Session.query(User.id, User.name, Message.id, Message.body).all()
How can i get back a list of User and Message objects, with all the
variables of those objects being None types except for what i selected in
the query.
ie. User<id = 23, name='John', last_login=None>, Message<id=123,
subject=None, body='what ever', date=None, creator_id=None>
This would help alot when i goto serialize my objects into JSON,... i am
trying to find an automatic way to serialize my queries into JSON but keep
the model/table data. ie.
{"User": { "id":23, "name":"John", "last_login":null}, "Message":
{"id":123, "subject":null, "body":"what ever", "date": null, creator_id:
null}, ..more rows }
If there is no way to actually return the model when specifying columns, im
guess there is a way to know what table that value came from, and construct
it that way?
Any ideas?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.