我可能沒有完全掌握@hybrid_property
的使用。但是我試圖做的就是使得基於另一個表中的列訪問計算值變得容易,因此需要連接。加入sqlalchemy混合財產
所以我已經是這樣的(這工作,但很彆扭,感覺錯了):
class Item():
:
@hybrid_property
def days_ago(self):
# Can I even write a python version of this ?
pass
@days_ago.expression
def days_ago(cls):
return func.datediff(func.NOW(), func.MAX(Event.date_started))
這需要我調用者增加對Action
表的連接,當我需要使用days_ago屬性。即使是我需要獲取days_ago值的簡化查詢的正確方法,hybrid_property是否也是如此?