I can't seem to figure this out - I need to define a self-referential
relationship on an table with a max of 25 items.
I use the following recipe often to handle this across tables, but I can't
seem to figure out how to do this with a single table as Aliased object
(which I'd use) is not allowed in the primaryjoin.
---
class DomainSuffix(DeclaredTable):
__tablename__ = 'domain_suffix'
id = sa_Column(sa_Integer, primary_key=True)
suffix = sa_Column(sa_Unicode(128), nullable=False, default=None)
domain_suffix_id__parent = sa_Column(sa_Integer,
sa_ForeignKey("domain_suffix.id"), nullable=True)
DomainSuffix.domain_suffix__children__max25 = sa_orm_relationship(
DomainSuffixAlias,
primaryjoin=(
and_(
DomainSuffix.id == DomainSuffixAlias.domain_suffix_id__parent,
DomainSuffixAlias.id.in_(
sqlalchemy.select([DomainSuffixAlias.id])\
.where(DomainSuffix.id ==
DomainSuffixAlias.domain_suffix_id__parent)\
.order_by(DomainSuffixAlias.suffix.asc())\
.limit(25)\
.correlate()
)
)
),
order_by=DomainSuffixAlias.suffix.asc(),
viewonly=True,
)
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.