Skip to content

Commit

Permalink
Order by id for derivedFrom relations to match graph-node
Browse files Browse the repository at this point in the history
  • Loading branch information
nikugogoi committed Nov 24, 2021
1 parent ddb9736 commit 96fcf56
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/graph-node/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export class Database {
if (isDerived) {
// For derived relational field.
condition = `${alias}.${derivedField} = entity.id AND ${alias}.block_number <= entity.block_number`;

selectQueryBuilder = selectQueryBuilder.addOrderBy(`${alias}.id`);
} else {
if (isArray) {
// For one to many relational field.
Expand All @@ -120,6 +122,8 @@ export class Database {
// For one to one relational field.
condition = `entity.${field} = ${alias}.id AND ${alias}.block_number <= entity.block_number`;
}

selectQueryBuilder = selectQueryBuilder.addOrderBy(`${alias}.block_number`, 'DESC');
}

if (isArray) {
Expand All @@ -128,14 +132,14 @@ export class Database {
relatedEntity,
alias,
condition
).addOrderBy(`${alias}.block_number`, 'DESC');
);
} else {
selectQueryBuilder = selectQueryBuilder.leftJoinAndMapOne(
`entity.${field}`,
relatedEntity,
alias,
condition
).addOrderBy(`${alias}.block_number`, 'DESC');
);
}
});

Expand Down

0 comments on commit 96fcf56

Please sign in to comment.