Hi guys,

I'm starting to use association proxies for the first time and I've come 
across an issue that has me stumped.

Basically, I want to use the association proxy's "creator" argument in 
order to create the intermediate object.
The intermediate object has foreign keys that point to the primary class 
(the one with the AP) and another 3rd class. 
So when creating that intermediate object, I want to be able to point to 
data within the primary objects instance (I need something for the FK 
column to point to!)

This is what I'm trying to do in code:
chars = association_proxy('char_links', 'char', creator=lambda c: CharLink(
word_id=self.id, char_id=c.id))

But obviously it doesn't work, because my uninstantiated class definition 
doesn't know what 'self' is.
This seems like something I should be able to do, as the creator function 
is only ever going to be called from an instance of my model (not just the 
class definition), so I should have access to the instance's props, no?

I've found this StackOverflow question that seems to be having the same 
problem, but the only answer seems hacky and to be honest I don't really 
understand it. 
<https://stackoverflow.com/questions/38284423/access-parent-object-from-sqlalchemy-association-proxy-creator>

Any tips?

~Connor


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to