Thank you,
Basically the multiple inheritance structure is a directional non-
cyclic graph (i looked at the graph example code in the distribution,
it uses methods to get next/previous nodes, which could serve as a
workaround, but seems inelegant) . Members are basically another name
for attributes.
I understand the need for the primaryjoin now. However the many to
many adjacency combination (graph) keeps eluding me. I would like to
use the association class so i can use what i learned for the members
class (types have multiple members, members have one type). Some more
questions:
1) Is associationproxy the only way to create an attribute that skips
the inheritance table, where do I indicate the primaryjoin then?
2) Is the point of a relationship() to make items in one class/table
accessible through an attribute in another class?
3) I am confused about the error I am getting in:

Base = declarative_base()

def _create_inheritance(supertype, subtype):
    return Inheritance(supertype, subtype)


class Inheritance(Base):
    __tablename__ = 'Inheritance'
    sub_name = Column(String(50), ForeignKey('Types.name'),
primary_key=True)
    super_name = Column(String(50), ForeignKey('Types.name'),
primary_key=True)
    def __init__(self, supertype, subtype):
        self.supertype = supertype
        self.subtype = subtype

class Types(Base):
    __tablename__ = 'Types'
    name = Column(String(50), primary_key=True)
    abstract = Column(Boolean)
    subtypes = association_proxy('Inheritance', 'subtypes', creator
=_create_inheritance)
    supertypes = association_proxy('Inheritance', 'supertypes',
creator = _create_inheritance)
    def __init__(self, name, abstract = False):
        self.name = name
        self.abstract = abstract
    def __repr__(self):
        return "Type(%r)" % (self.name)

engine = create_engine('sqlite:///:memory:', echo=True)
Base.metadata.create_all(engine)


if __name__ == "__main__":
    Session = sessionmaker(bind=engine)
    session = Session()

    c1 = Types("A")
    c2 = Types("B")
    c3 = Types("C")
    c1.subtypes.append(c2)  #<=ERROR
    c3.supertypes.append(c1)

With the Error:

Traceback (most recent call last):
  File "D:\Documents\Code\NetBeans\test\Alchemy\src\alchemy.py", line
63, in <module>
    c1.subtypes.append(c2)
  File "C:\Python27\lib\site-packages\sqlalchemy\ext
\associationproxy.py", line 164, in __get__
    self.scalar = self._target_is_scalar()
  File "C:\Python27\lib\site-packages\sqlalchemy\ext
\associationproxy.py", line 156, in _target_is_scalar
    return not self._get_property().uselist
  File "C:\Python27\lib\site-packages\sqlalchemy\ext
\associationproxy.py", line 148, in _get_property
2011-02-20 16:12:12,595 INFO sqlalchemy.engine.base.Engine.0x...ef0L
COMMIT
    get_property(self.target_collection))
  File "C:\Python27\lib\site-packages\sqlalchemy\orm\mapper.py", line
933, in get_property
    (self, key))
sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper|Types|Types' has no
property 'Inheritance'

What does this mean?

Actually I am getting confused in general about how to implement the
combination of many to many relationships on the same table. Please
help.


-- 
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.

Reply via email to