Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
adding an association_proxy to mapper properties?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gerald Thibault  
View profile  
 More options Nov 16 2012, 1:05 am
From: Gerald Thibault <dieselmach...@gmail.com>
Date: Thu, 15 Nov 2012 22:05:43 -0800 (PST)
Local: Fri, Nov 16 2012 1:05 am
Subject: adding an association_proxy to mapper properties?

I have an association proxy set up to proxy an attribute from a parent to a
one to one child. That proxied column does not show when I do
class.__mapper__.iterate_properties. How would I go about adding a property
so the proxied columns are exposed via iterate_properties?

I'll add some code if necessary, but this seems like a pretty
straight-forward question that I probably just overlooked in the docs.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Bayer  
View profile  
 More options Nov 16 2012, 9:08 pm
From: Michael Bayer <mike...@zzzcomputing.com>
Date: Fri, 16 Nov 2012 21:08:22 -0500
Local: Fri, Nov 16 2012 9:08 pm
Subject: Re: [sqlalchemy] adding an association_proxy to mapper properties?

On Nov 16, 2012, at 1:05 AM, Gerald Thibault wrote:

> I have an association proxy set up to proxy an attribute from a parent to a one to one child. That proxied column does not show when I do class.__mapper__.iterate_properties. How would I go about adding a property so the proxied columns are exposed via iterate_properties?

> I'll add some code if necessary, but this seems like a pretty straight-forward question that I probably just overlooked in the docs.

the mapper().iterate_properties accessor only refers to MapperProperty objects, which are all of those attributes that the mapper() associates with the database in some way.

the association proxy is not a MapperProperty - it is just a Python descriptor that has proxying behavior from one attribute to another.   It can in theory be used to proxy data between any two attributes, independently of SQLAlchemy (there might be a few bits of logic that look for SQLAlchemy-related attributes to help it decide how the proxying should be done, though).

If you're looking to iterate through the attributes associated with the class, the Python dir() function can get you this.  You can limit the results to those classes you need using isinstance():

def properties():
    for attr in dir(MyClass):
       if hasattr(attr, "property"):
            yield attr.property
      elif isinstance(attr, association_proxy):
           yield attr


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »