I am building a tree datastructure using parent pointers. The only differece
from a standard adjancancy list is that I can have multiple trees, each
identified by a root session node. In order to be allow fast queries each tree
node has a pointer to the session id (ie the root node).
Unfortunately I can't seem to get the relation declared properly. My latest
attempt looks like this:
------------------------------------------------------------------------
import sqlalchemy
from sqlalchemy import orm
from sqlalchemy import schema
from sqlalchemy import types
from sqlalchemy.ext.declarative import declarative_base
session = orm.create_session()
db_engine = sqlalchemy.create_engine("sqlite:///")
BaseObject = declarative_base()
class TreeNode(BaseObject):
__tablename__ = "tree"
id = schema.Column(types.Integer(), primary_key=True, autoincrement=True)
type = schema.Column(types.String(10), nullable=False, index=True)
session_id = schema.Column(types.Integer(),
schema.ForeignKey("session.id", onupdate="CASCADE", ondelete="CASCADE"),
nullable=False, index=True)
parent_id = schema.Column(types.Integer(),
schema.ForeignKey("tree.id", onupdate="CASCADE", ondelete="CASCADE"),
nullable=True, index=True)
__mapper_args__ = dict(polymorphic_on=type)
session = orm.relation("SurveySession", cascade="all",
remote_side=["SurveySession.id"],
primaryjoin="SurveySession.id==TreeNode.session_id")
parent = orm.relation("TreeNode", cascade="all",
remote_side=["TreeNode.id"],
primaryjoin="TreeNode.id==TreeNode.parent_id")
class SurveySession(TreeNode):
__tablename__ = "session"
__mapper_args__ = dict(polymorphic_identity="session")
id = schema.Column(types.Integer(), primary_key=True, autoincrement=True)
query=session.query(TreeNode)
print query.all()
------------------------------------------------------------------------
but running that results in this error message:
sqlalchemy.exc.ArgumentError: Relation TreeNode.parent could not determine any
local/remote column pairs from remote side argument
set([<sqlalchemy.sql.expression.ColumnClause at 0x1120bd0; TreeNode.id>])
I can't seem to figure out what the correct spelling is.
Wichert.
--
Wichert Akkerman <[email protected]> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---