On Wed, Sep 5, 2018 at 7:19 PM, Connor <connor...@gmail.com> wrote:
> 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))
>

normally you are using associationproxy with relationships so you
don't need to set foreign key attributes directly.  Assuming
"char_links" and "char" are relationships there is no need to set
those attributes, they will be set for you.




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

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