I have "this allready" at compile-time. But at run-time I will have to deal with instances of different classes dinamically. So I need to inspect the instances to find out if they are linked to others or not, and what is that they are linked to. Something like this:
*def *print_related_records(instance): related_classes = *find_related_classes*(instance.__class__) * #returns {'children':Child}* *#iterate the related_classes dict, query all the related records, then print them* ... john = Parent('John Smith') betty = Child('Betty') john.children.append(betty) ... print_related_records(john) *#prints 'Betty'* print_related_records(betty) *#prints nothing* On Wednesday, December 12, 2012 2:41:51 PM UTC+2, Juan Hernandez wrote: > > I'm not sure I get your question... > > if you have this already > > children = relationship("Child") > > what is it that you need to know?? > > By using MyClass.children you'll have access to it's children and they > will be, one2many relationships > > > > > On Wed, Dec 12, 2012 at 4:57 AM, AlexVhr <vih...@gmail.com > <javascript:>>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: >> >> *class* *Parent*(Base):**** >> >> __tablename__ = 'parent'**** >> >> id = Column(Integer, primary_key=True)**** >> >> children = relationship("Child") >> >> >> *class* *Child*(Base):**** >> >> __tablename__ = 'child'**** >> >> id = Column(Integer, primary_key=True)**** >> >> parent_id = Column(Integer, ForeignKey('parent.id'))**** >> >> >> 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!**** >> >> -- >> 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/-/LaLdjo3_XoUJ. >> To post to this group, send email to sqlal...@googlegroups.com<javascript:> >> . >> 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/-/J_O3rEoUpa8J. 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.