需要在引用属性中按属性排序,有什么好的解决方案? [英] Need to order by properties in the reference property, any good solution?
本文介绍了需要在引用属性中按属性排序,有什么好的解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有2种:
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
该怎么做?
参考: http://www.mail-archive .com/google-appengine @ googlegroups.com/msg15878.html
推荐答案
数据存储区中没有与该查询相当的项目.一些要点:
There's no equivalent for that query in datastore. Some points:
- 您不能选择一个属性.
SELECT
始终为SELECT *
(您选择整个实体). - 您不能加入.您需要对模型进行非规范化以适合您要执行的查询,或者执行多个查询.
- You can't select a single property.
SELECT
is alwaysSELECT *
(you select a whole entity). - You can't do joins. You need to denormalize your models to fit the queries you will perform, or perform multiple queries.
因此,要实现您的目标,您需要将last_login
存储在Relationship
中,或使用第3个模型作为该特定查询的索引.
So to achieve your goal, you need to have last_login
stored in Relationship
, or have a 3rd model to serve as index for that specific query.
这篇关于需要在引用属性中按属性排序,有什么好的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文