On Dec 7, 2011, at 7:53 PM, Hector Blanco wrote:

> Hello everyone:
> 
> In one of my classes, I am using an associationproxy to provide a list
> in which the same item can be inserted twice. Basically, a product can
> contain "images" (several times the same image).  One product can have
> two different lists of "images" (images1 and images2... yep... not
> very creative with the naming here)
> 
> Is there a way, given a class Product (or an instance, but preferably a
> class) knowing that Product._images1 (or Product._images2) is going to
> give me "Image"s (er... things of class "Image"). I've been able to do
> that with regular relationships through [relationship].mapper.class_.



associationproxy has an attribute target_class for the "middle" class: 

MyClass.my_association.target_class

then for the target, 0.7 has "remote_attr".  Not in 0.6 but it's just shorthand 
for:

getattr(MyClass.my_association.target_class, self.value_attr)

but AP doesn't know what type that is.  Suppose it were a relationship, then 
you'd say:

getattr(MyClass.my_association.target_class, 
MyClass.my_association.value_attr).property.class_

if a column:

getattr(MyClass.my_association.target_class, 
MyClass.my_association.value_attr).property.columns[0]

etc.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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