I'm thinking of JOIN with the parents, but failed. Because joining
indefinite levels seems to be very hard to implement. You don't know how
many levels you need to look up until you find a parent with a non Null
value for that optional column. How to approach this problem?
On Friday, October 14, 2016 at 3:08:32 PM UTC-7, Jinghui Niu wrote:
> I have the following Table model representing a timeline.
> class TimeRange(Base):
> __tablename__ = "time_line"
> record_id = Column(Integer, primary_key=True)
> level = Column(String, nullable=False) # e.g. "Point", "Range"
> content = Column(String, nullable=False)
> language_marker = Column(String) # this one column is optional and
> needs to be queried
> immediate_parent_id = Column(Integer, ForeignKey('time_line.record_id'
> child_timelines = relationship('TimeRange', backref=backref(
> 'parent_timeline', remote_side=[record_id]))
> The language_marker Column is the one that needs to be queried in a
> recursive manner. Not all records have such an attribute, and the business
> logic is: along the hierarchy lineage from the root down to the child
> timelines, at least one level of the TimeRange instance carries such an
> attribute, and the one in the lowest level should be returned. This works a
> little like cascading style sheet, where if the TimeRange object itself
> doesn't have such an attribute, just look further up one level above, util
> found one, and the latest defined style wins.
> What is the technical direction I should look into to implement such
> queries? I'm using SQLAlchemy and the backend is SQLite. Thanks.
The Python SQL Toolkit and Object Relational Mapper
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
To unsubscribe from this group and stop receiving emails from it, send an email
To post to this group, send email to firstname.lastname@example.org.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.