Thread.posts = relation(Post, order_by=Post.position.asc(), lazy='dynamic', backref='thread')
Thread.first_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == 1), foreign_keys=[Post.thread_id], innerjoin=True, uselist=False, viewonly=True)
Thread.posts = relation(Post, order_by=Post.position.asc(), lazy='dynamic', backref='thread')
Thread.first_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == 1), foreign_keys=[Post.thread_id], innerjoin=True, uselist=False, viewonly=True)