On Nov 16, 2010, at 11:43 AM, Michael Bayer wrote:

> 
> On Nov 16, 2010, at 11:14 AM, A.M. wrote:
> 
>> Hello,
>> 
>> 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?
> 
> 1. why not use dir(myobject) to get a view of your object as a whole ?

We swiped "dictify" from sprox.saormprovider:
http://bitbucket.org/percious/sprox/src/tip/sprox/saormprovider.py#cl-321

We like the behavior that a REST call to retrieve an SQLAlchemy object returns 
pks for relationships (instead of loading the entire result hierarchy), so 
subsequent REST calls are required to dig deeper into the "tree" of results.

Using dir() is definitely a good suggestion which I will try. You are probably 
right that we are using iterate_properties improperly.

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

Cheers,
M

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