0

根据 Googles Documentation,空值没有排序顺序。有没有办法配置这种行为。例如,如果我按升序对整数属性进行排序,是否可以将数据存储配置为最后或第一个返回空值?

4

1 回答 1

1

您最好的选择可能是将属性另存为空白“”字符串,用于每个具有该属性的空值的实体。请务必在您更改的每个实体上运行 put()。

employees = Employee.all().fetch(50)
for employee in employees:
    if employee.hobbies is None: # Null value property
        employee.hobbies = ""
        employee.put()

当然,这不是执行此任务的最有效方式。您可能想要创建一个列表对象,例如“batch_put_list”,并将每个员工对象附加到列表中。然后,执行 db.put(batch_put_list)。

batch_put_list = []
employees = Employee.all().fetch(50)
for employee in employees:
    if employee.hobbies is None:
        employee.hobbies = ""
        batch_put_list.append(employee)
db.put(batch_put_list)

希望这可以帮助。

于 2012-06-09T15:22:29.237 回答