Hi all,

I tried to convert some existing code containing an adjacency list to
mix-ins, and the mix-in version doesn't seem to be liked by SQLAlchemy
0.6_beta1:

Original code that works:

class ClassDefaults(DeclarativeMeta):
       def __init__(cls,classname, bases, dict_):
               dict_['id'] = Column(Integer, Sequence("id_seq",
optional=True), primary_key=True)
               return DeclarativeMeta.__init__(cls, classname, bases, dict_)

Base = declarative_base(metaclass=ClassDefaults)

class Location(Base):
        __tablename__ = 'location'
        parent_id = Column(Integer, ForeignKey('location.id'))
        parent = relation('Location', backref=backref('children'),
remote_side='location.c.id')
        name = UniqueString(25)
        desc = Column(String(80))

New Mix-In code that doesn't work:

Base = declarative_base()

class Common(object):
        id = Column(Integer, Sequence('id_seq', optional=True),
primary_key=True)

class Location(Base,Common):
        __tablename__ = 'location'
        parent_id = Column(Integer, ForeignKey('location.id'))
        parent = relation('Location', backref=backref('children'),
remote_side='location.c.id')
        name = UniqueString(25)
        desc = Column(String(80))

SQLAlchemy complains:

Traceback (most recent call last):
  File "base.py", line 60, in <module>
    class Location(Base,Common):
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/ext/declarative.py",
line 561, in __init__
    _as_declarative(cls, classname, dict_)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/ext/declarative.py",
line 554, in _as_declarative
    cls.__mapper__ = mapper_cls(cls, table, properties=our_stuff, **mapper_args)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/__init__.py",
line 778, in mapper
    return Mapper(class_, local_table, *args, **params)
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/mapper.py",
line 189, in __init__
    self._configure_pks()
  File "/usr/lib64/python2.6/site-packages/sqlalchemy/orm/mapper.py",
line 435, in _configure_pks
    "key columns for mapped table '%s'" % (self, self.mapped_table.description))
sqlalchemy.exc.ArgumentError: Mapper Mapper|Location|location could
not assemble any primary key columns for mapped table 'location'

Question: do Mix-ins complicate the mechanism by which adjacency lists
are defined? If so, how does one work around this (and maybe update
the Mix-in docs to show an example of how to work around this issue?)

Thanks,

Daniel

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.

Reply via email to