On Wed, Jun 6, 2018 at 6:03 PM, Colton Allen <[email protected]> wrote: > In an after_insert event I'm trying to load the value of an > "orm.relationship". The foreign-key column has a value but it returns null. > Is there a way to force it to load? > > model = Model(user_id=1) # some model is created with a foreign-key > > @event.listens_for(Model, 'before_insert') > def print_user(connection, mapper, target): > print(target.user) # None - desired: <UserModel 0x00....> > print(target.user_id). # 1 >
that looks like before_insert. for after_insert, target.user_id should be set, assuming target.user was set to something (and that user_id is the FK for a many to one target.user). > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
