Can't execute a distinct projection query

后端 未结 1 442
花落未央
花落未央 2021-01-25 00:42

I have a simple little \"Observation\" class:

from google.appengine.ext import ndb

class Observation(ndb.Model):
    remote_id = ndb.StringProperty()
    dimens         


        
1条回答
  •  再見小時候
    2021-01-25 00:59

    Silly me - all of these params need to sit within the query() function, not within fetch(). The projection elements actually works in fetch(), but you need to move both the projection and distinct arguments into query() to get it to work.

    From Grouping:

    Projection queries can use the distinct keyword to ensure that only completely unique results will be returned in a result set. This will only return the first result for entities which have the same values for the properties that are being projected.

    Article.query(projection=[Article.author], group_by=[Article.author])
    Article.query(projection=[Article.author], distinct=True)
    

    Both queries are equivalent and will produce each author's name only once.

    Hope this helps anyone else with a similar problem :)

    0 讨论(0)
提交回复
热议问题