Hi,
I would like to create an abstract model which should be inherited.
Unfortunately, I am not allowed to used Foreign Keys, this is the reason
why I introduced work around via relationship. Here is the whole code:
class DepTest(db.Model):
__tablename__ = u'deptest'
__bind_key__ = u'section'
department_pk_id = db.Column(db.Integer, primary_key=True)
department_id = db.Column(db.Integer)
department_name = db.Column(db.String(1000))
class PPLTest(db.Model):
__abstract__ = True
person_pk_id = db.Column(db.Integer, primary_key=True)
person_name = db.Column(db.String(1000))
person_surname = db.Column(db.String(1000))
department_id = db.Column(db.Integer)
@hybrid_property
def person_name_surname(self):
return self.person_name + u' ' + self.person_surname
class Level1(PPLTest):
__tablename__ = u'ppl_level1'
__bind_key__ = u'section'
department = relationship(
DepTest,
primaryjoin=remote(DepTest.department_id) == foreign(
PPLTest.department_id))
But I get "Cannot compile Column object until its 'name' is assigned."
So I defined department (in Level1) using @declared_attr:
def department(clss):
return relationship(DepTest,
primaryjoin=lambda:
remote(DepTest.department_id) == foreign(
clss.department_id)
)
and now it works as expected. The question is - is it defined properly,
or I should be aware of sth?
Thank you for any suggestions!
Cheers
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.