On Dec 12, 2012, at 4:27 AM, AlexVhr wrote: > Hi all. > I need to find out if a certain class has one-to-many relations to other > classes, and what exactly this classes are. Something like this: > I'm kind of half way there: > > def findRelatedClasses(cls): > #iterate cls.__dict__, find a class member with > #property.direction.name == ‘ONETOMANY’. > #Now, to find out which class it links to… > > > findRelatedClasses(Parent) should return a list of type objects ([Child] in > this instance). Any ideas how to do that? Thanks! >
property.mapper is the target Mapper and mapper.class_ is the class which is mapped. in 0.7 you want to use class_mapper(cls).iterate_properties() to get at MapperProperty, don't bother with __dict__ (and even then I'd be using dir()/getattr() to deal with descriptors). There's an improved introspection interface in 0.8, see: http://docs.sqlalchemy.org/en/rel_0_8/core/inspection.html , you'd use inspect(cls).relationships. -- 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.