hi
i'm trying to make a metainfo extractor off some relation attribute.
by metainfo i mean the klas and attr-name of this and of the other
side of the relation-attribute, or of the parent or child of the
relation regardless the start point.
e.g. possible usage and testing invariants is like:
a = about_relation( someklas.someproperty)
print a.name, a.klas, 'is_parent:', a.is_parent
assert a.thisside == a
b = a.otherside
print b.name, b.klas, 'is_parent:', b.is_parent
assert a.otherside.otherside == a
if a.is_parent:
assert a.child is a.otherside
assert a.parent is a.thisside
else:
assert a.parent is a.otherside
assert a.child is a.thisside
e.g. if Parent.kids / Kid.parent are 1:many:
print about_relation( Parent.kids).otherside.name -> 'mama'
print about_relation( Parent.kids).otherside.klas -> 'Kid'
print about_relation( Parent.kids).child.klas -> 'Kid'
print about_relation( Kid.parent).child.klas -> 'Kid'
print about_relation( Kid.parent).parent.klas -> 'Parent'
print about_relation( Kid.parent).otherside.name -> 'kids'
etc... u get the idea.
is there such functionality in SA?
After digging about a day, now it sort of works, but i'm musing if
i've found the correct way to extract the info.
here my pseudocode rules (klas_attr is the input: someklas.someattr):
...
impl = klas_attr.impl
thisside.is_parent= isinstance( impl, CollectionAttributeImpl)
prop = klas_attr.property
thisside.klas = impl.class_
thisside.name = prop.key
otherside.klas = prop.mapper.class_
revprop = prop._reverse_property
if revprop is None:
otherside.no_backref = True
if not otherside.is_parent: # == not thisside.parent
otherside.name = list( prop.remote_side )[0].key #column-name!
else:
otherside.name = None
else:
otherside.no_backref = False
otherside.name = revprop.key
if thisside.is_parent: parent,child = thisside,otherside
else: child,parent = thisside,otherside
------------
is this ok?
i've tried it on 1:many relations, will it work on 1:1 / many2many?
ciao
svilen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---