So, I have the following situation. I have a DataTypes class that has the 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 the relationships defined here are working. But now I have some specific data types that are created dynamically through introspection and which also need to be excluded. They are created as follows:
t = Table('DATA_' + obj.__name__.lower(), *t[:-1], **t[-1])
mapper(obj, t, *args, **kwargs)
model.Base.metadata.create_all(dao.Engine)
This works great, and tables are created as needed. But now I want to add relationships in the same way as from the DataType class. So I 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 it gives me:
sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Original exception was: relationship 'children' expects a class or a mapper argument (received: <type 'str'>)
I am very new to SQLAlchemy. Any suggestions?
Regards, Bogdan