Need to order by properties in the reference property, any good solution?

Let's say I have 2 types:

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 the following query:

SELECT target 
FROM Relationship
WHERE owner = :key AND type = :type
ORDERBY target.last_login DESC 

How to do it?

link: http://www.mail-archive.com/ google-appengine@googlegroups.com /msg15878.html

+3
source share
1 answer

There is no equivalent for this query in the data warehouse. Some moments:

  • You cannot select one property. SELECTalways SELECT *(you select the whole entity).
  • You cannot join. You must denormalize your models according to the queries that you will fulfill, or fulfill several queries.

, last_login, Relationship, , .

+6

Source: https://habr.com/ru/post/1756518/


All Articles