我正在尝试仅获得已批准的回复(已暂存> 1)但由于某种原因,主要连接中的Reply.staged> 1无法正常工作
我对sqlAlchemy很新,所以我不确定父母与remote_side的关系是什么
class Story(Base):
__tablename__ = ’Story'
id = Column(‘ID', Integer, primary_key=True)
anonymous = Column(TINYINT)
detail = Column('detail',String, js_name='detail')
summary = Column('summary',String, js_name='questionSummary')
user_id = Column('uid', Integer, ForeignKey('rlUser.uid'), js_name='userId')
user = relationship("User")
inspire_id = Column('inspireID', Integer, js_name='inspireId')
staged = Column(TINYINT)
class Reply(Base):
__tablename__ = 'Reply'
id = Column('replyID', Integer, primary_key=True)
parent_id = Column('parentID', Integer, ForeignKey('rlReply.replyID'),js_name='parentId')
user_id = Column('userID', Integer, js_name='userId')
detail = Column(String, js_name='detail')
reply_date = Column('replyDate', TIMESTAMP, js_name='replyDate')
expertise_type = Column('expertiseType', Integer, js_name='expertiseType')
status = Column(Integer)
staged = Column(Integer)
story = relationship(“Story",primaryjoin='and_(Reply.story_id == Story.id, Reply.parent_id==0, Reply.staged>1)', backref=backref("replies", uselist=True ))
parent = relationship('Reply',primaryjoin='and_(Reply.parent_id==Reply.id, Reply.staged>1)', backref='responses', remote_side='Reply.id', viewonly=True, uselist=True)
def __init__(self):
self.staged = constants.POST_QUEUE_STATUS['STAGED']
@property
def reply_count(self):
return len(self.responses)
story.replies的where子句:
WHERE Reply
。rushlineID
=%s AND Reply
。parentID
=%s AND Reply
。staged> %S
parms sqlalchemy.engine.base.Engine(110L,0,1)
然而,这是完美的:
story.replies [0]的where子句。响应:
在哪里Reply
。parentID
=%s AND%s> %S
params是sqlalchemy.engine.base.Engine(68L,2,1)
我需要的是WHERE Reply
。parentID
=%s AND AND Reply
。staged> %s AND%s> %S
sqlalchemy.engine.base.Engine(68L,1,2,1)
答案 0 :(得分:0)
这个神奇的咒语,我不得不承认,我经历了试验和很多错误。以下是相关内容:
parent_id = RlColumn('parentID', Integer, ForeignKey('rlReply.replyID'), js_name='parentId')
parent = RlRelationship('Reply', primaryjoin='and_(Reply.parent_id==remote(Reply.id),Reply.flagged_status <2)',remote_side=id, uselist=True, foreign_keys=parent_id, backref='replies')