On Tue, Nov 16, 2010 at 9:05 AM, A.M. <age...@themactionfaction.com> wrote:
>
> On Nov 16, 2010, at 11:43 AM, Michael Bayer wrote:
>
>>
>> On Nov 16, 2010, at 11:14 AM, A.M. wrote:
>>> To generate json from our SQLAlchemy model objects, we are using 
>>> iterate_properties to determine how to "dictify" the object. One of our 
>>> objects uses association_proxy which we would like to represent in the 
>>> JSON. Unfortunately, because it is not a property, the dictification misses 
>>> this property. I feel like I am missing something simple here.
>>>
>>> How can I make an association_proxy appear to be a property which appears 
>>> in iterate_properties of the mapper?
>>
>> 2. implicit conversion to JSON and such is a little sloppy.   You'd be 
>> better off using a structured approach like Colander: 
>> http://docs.repoze.org/colander/
>
> It looks like I would have to either re-define all objects using the Colander 
> syntax or implement a method which converts existing SQLAlchemy models to 
> Colander schema objects. Even if the latter function already exists, I still 
> have the problem of determining automatically which properties to encode, no?

You may find you'll need to do even further work to determine which
properties to encode.  I do the same (using Flatland for
serialization), and part of that challenge was determining where the
edges of the business objects were.  (If you have relations, maybe
some of them are part of the object (as user's email addresses) and
some of them aren't (a User->Users list of the user's friends). In the
end I went with a combination of class annotation and heuristics based
on iterating mapper properties.  This allowed me to traverse the
mappings to reliably find the edges and also include the occasional
transient attribute or other oddball that needed to be in the
serialized form.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to