On Wed, Dec 9, 2009 at 10:11 AM, Sergey Koval <[email protected]> wrote:
> Hi, > > I'm trying to get relation type from the mapper, but having problems > detecting 'one to one' relation. > > Pseudo code: > for p in mapper.iterate_properties: > if isinstance(p, RelationProperty): > ... > > p.uselist is False, p.backref is available, but does not have any > information on it's type (should it use list or not). > p.direction is set to 'MANYTOONE'. > > How it can be accomplished? > > Thanks, > Serge. > > Interesting question. It looks like you can use the backref property to discover the other side of the relation via the backref.prop attribute. From there you should be able to find the the property on the other side by examining the mapper on that class and view it's uselist property also. I'm not sure how you would find the right relation if there were 2 relations between the classes. There might be a simpler approach, but it looks like this one should work. -- Mike Conley -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
