I have these 2 entities in objectbox:
<code>@Entity()
class Account {
@Id()
int id = 0;
}
@Entity()
class Transaction {
@Id()
int id = 0;
final fromAccount = ToOne<Account>();
final toAccount = ToOne<Account>();
}
</code>
<code>@Entity()
class Account {
@Id()
int id = 0;
}
@Entity()
class Transaction {
@Id()
int id = 0;
final fromAccount = ToOne<Account>();
final toAccount = ToOne<Account>();
}
</code>
@Entity()
class Account {
@Id()
int id = 0;
}
@Entity()
class Transaction {
@Id()
int id = 0;
final fromAccount = ToOne<Account>();
final toAccount = ToOne<Account>();
}
I need to query all transactions from or to a particular account. I’m unable to figure out the query. Tried this but it doesn’t work:
<code>Future<List<Transaction>> getAllTransactionsForAccount(int accountId) {
QueryBuilder<Transaction> builder = box.query();
builder.link(
Transaction_.toAccount, Account_.id.equals(accountId));
builder.link(
Transaction_.fromAccount, Account_.id.equals(accountId));
Query<Transaction> q = builder.build();
return q.findAsync();
}
</code>
<code>Future<List<Transaction>> getAllTransactionsForAccount(int accountId) {
QueryBuilder<Transaction> builder = box.query();
builder.link(
Transaction_.toAccount, Account_.id.equals(accountId));
builder.link(
Transaction_.fromAccount, Account_.id.equals(accountId));
Query<Transaction> q = builder.build();
return q.findAsync();
}
</code>
Future<List<Transaction>> getAllTransactionsForAccount(int accountId) {
QueryBuilder<Transaction> builder = box.query();
builder.link(
Transaction_.toAccount, Account_.id.equals(accountId));
builder.link(
Transaction_.fromAccount, Account_.id.equals(accountId));
Query<Transaction> q = builder.build();
return q.findAsync();
}
If I remove one of fromAccount
or toAccount
, it works.
Could someone help please ?