Hi,
i'm trying to add a column property with where clause that depends on other
2 column properties (see JobItem.nested_quantity) in the attached file) but
looks like it's not possible.
Any ideas if it's possible to achieve same result one way or another ?
Thanks
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
class Project(DB.Model):
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
class NestingSheetLayout(DB.Model):
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
project_id = sa.Column(None, sa.ForeignKey(Project.id, ondelete='CASCADE'))
project = orm.relationship(Project,
backref=orm.backref('nesting_sheet_layouts', cascade='all,delete-orphan', passive_deletes=True))
class NestingSheetLayoutItem(DB.Model):
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
quantity = sa.Column(sa.Integer)
nesting_sheet_layout_id = sa.Column(None, sa.ForeignKey(NestingSheetLayout.id, ondelete='CASCADE'))
nesting_sheet_layout = orm.relationship(NestingSheetLayout,
backref=orm.backref('items', cascade='all,delete-orphan', passive_deletes=True))
@declared_attr
def project_id(cls):
return orm.column_property(
sa.select(
[NestingSheetLayout.project_id],
NestingSheetLayout.id==cls.nesting_sheet_layout_id
),
)
class Job(DB.Model):
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
project_id = sa.Column(None, sa.ForeignKey(Project.id))
project = orm.relationship(Project,
backref=orm.backref('jobs', cascade='all, delete-orphan'))
class JobItem(DB.Model):
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
job_id = sa.Column(None, sa.ForeignKey(Job.id, ondelete='CASCADE'))
job = orm.relationship(Job, lazy=True,
backref=orm.backref('items', cascade='all', passive_deletes=True))
quantity = sa.Column(sa.Integer)
@declared_attr
def project_id(cls):
return orm.column_property(
sa.select([Job.project_id], Job.id==cls.job_id),
)
@declared_attr
def nested_quantity(cls):
return orm.column_property(
sa.select(
[sa.func.sum(NestingSheetLayoutItem.quantity)],
(
(cls.project_id==NestingSheetLayout.project_id) &
(cls.part_id == NestingSheetLayoutItem.part_id)
)
)
)