所以每次我执行下面的查询api而不是列出用户创建的所有费用时,它会创建一个新的费用吗?
@ApiMethod(
name = "getMyExpenses",
path = "getMyExpenses",
httpMethod = ApiMethod.HttpMethod.POST
)
public List<Expense> getMyExpenses(final User user) throws UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("You need to authorisation");
}
String userId = user.getUserId();
Key<Person> personKey = Key.create(Person.class, userId);
return ofy().load().type(Expense.class).ancestor(personKey).list();
}
我不确定为什么会这样。任何帮助表示赞赏。
问题可能在于我如何尝试定义父关系?这是我的Expense模型类。
@Entity
public class Expense {
@Id Long ExpenseId;
String name;
@Parent
Ref<Person> ExpenseCreator;
int amount;
private Expense() {}
public Expense(Long expenseId, String name, int amount) {
ExpenseId = expenseId;
this.name = name;
this.amount = amount;
}
public Long getExpenseId() {
return ExpenseId;
}
public String getName() {
return name;
}
public int getAmount() {
return amount;
}
}