Thank you! That is exactly the function I needed.
On Tuesday, November 13, 2012 9:16:47 PM UTC-8, Michael Bayer wrote:
On Nov 13, 2012, at 11:03 PM, Bobby Impollonia wrote:
I have constructed a sample program consisting of two mapped classes
(using sqlalchemy.ext.declarative) that have a relationship/ backref
between them. At runtime the program does the following:
1) Print whether the parent class has an attribute for its relationship to
the child (declared as the backref)
2) Construct a child object
3) Repeat step 1
The result (with SQLA 0.7.9) is that it prints 'False' during step 1 and
then 'True' during step 3. I would expect True to be printed both times.
Here is the full source of the program:
https://gist.github.com/4070161
Why does the property not exist when the first print statement executes?
addresses is generated on the Person class when the mappers enter the
configuration step, which is an automatically invoked process which
occurs when a mapping is first used. this process is deferred until a
point at which it's safe to assume all mappings are present, so that
relationship() directives, which refer to other mappings, can proceed to
reconcile the mappings they point to - otherwise by definition one of the
mappings/classes (if using declarative) doesn't exist yet for
relationship/backref.
the process can be manually invoked via configure_mappers():
if __name__ == '__main__':
from sqlalchemy.orm import configure_mappers
configure_mappers()
print hasattr(Person, 'addresses')
Address()
print hasattr(Person, 'addresses')
Thanks for any guidance.
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/SRZzsLt7qb0J.
To post to this group, send email to sqlal...@googlegroups.comjavascript:
.
To unsubscribe from this group, send email to
sqlalchemy+...@googlegroups.com javascript:.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.
--
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/-lPqaGoaWcYJ.
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.