需要按参考属性中的属性排序,有什么好的解决方案吗?
假设我有两种:
class Account(db.Model):
name = db.StringProperty()
create_time = db.DataTimeProperty()
last_login = db.DateTimeProperty()
last_update = db.DataTimeProperty()
class Relationship(db.Model)
owner = db.ReferenceProperty(Account)
target = db.ReferenceProperty(Account)
type = db.IntegerProperty()
我想获得以下查询的等价物:
SELECT target
FROM Relationship
WHERE owner = :key AND type = :type
ORDERBY target.last_login DESC
如何做到这一点?
Say I have 2 kind:
class Account(db.Model):
name = db.StringProperty()
create_time = db.DataTimeProperty()
last_login = db.DateTimeProperty()
last_update = db.DataTimeProperty()
class Relationship(db.Model)
owner = db.ReferenceProperty(Account)
target = db.ReferenceProperty(Account)
type = db.IntegerProperty()
I want to get the equivalence of following query:
SELECT target
FROM Relationship
WHERE owner = :key AND type = :type
ORDERBY target.last_login DESC
How to do that?
reference: http://www.mail-archive.com/[email protected]/msg15878.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
数据存储区中没有该查询的等效项。几点:
SELECT
始终为SELECT *
(您选择整个实体)。因此,为了实现您的目标,您需要将
last_login
存储在Relationship
中,或者有第三个模型作为该特定查询的索引。There's no equivalent for that query in datastore. Some points:
SELECT
is alwaysSELECT *
(you select a whole entity).So to achieve your goal, you need to have
last_login
stored inRelationship
, or have a 3rd model to serve as index for that specific query.