python - Problem with sqlAlchemy model -
so have following situation. have class datatypes has following structure:
class datatype(base): __tablename__ = 'data_types' id = column(integer, primary_key=true) type_name = column(string) fk_result_storage = column(integer, foreignkey('data_storages.id')) parentdatastorage = relationship("datastorage", backref=backref("datatype", cascade="all,delete")) def __init__(self, name, resultid): self.type_name = name self.fk_result_storage = resultid
now relationship defined here works. have specific data types created dynamically trough introspection , need deleted cascaded also. created this:
t = table('data_' + obj.__name__.lower(), *t[:-1], **t[-1]) mapper(obj, t, *args, **kwargs) model.base.metadata.create_all(dao.engine)
this works fine , tables created needed. want add relationship similar 1 datatype class. tried this:
t = t('data_' + obj.__name__.lower(), *t[:-1], **t[-1]) m(obj,t,properties = {'children' : relationship('datatype', backref=backref(obj, cascade="all,delete"))} ) model.base.metadata.create_all(dao.engine)
but gives me:
sqlalchemy.exc.invalidrequesterror: 1 or more mappers failed initialize - can't proceed initialization of other mappers. original exception was: relationship 'children' expects class or mapper argument (received: <type 'str'>)
i`m quite new sqlalchemy. suggestions ?
regards, bogdan
sqlalchemy not strongest skill, think property wrong:
properties = {'children' : relationship('datatype', backref=backref(obj, cascade="all,delete"))}
i think should be:
properties = {'children' : relationship(datatype, backref=backref(obj, cascade="all,delete"))}
i.e., reference datatype class, not string.
Comments
Post a Comment