Skip to content

Commit

Permalink
fix(knex): ensure virtual properties are never part of returning cl…
Browse files Browse the repository at this point in the history
…ause

Closes #3664
  • Loading branch information
B4nan committed Oct 31, 2022
1 parent b1a867d commit 35d51fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/knex/src/AbstractSqlDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export abstract class AbstractSqlDriver<C extends AbstractSqlConnection = Abstra

if (this.platform.usesReturningStatement()) {
/* istanbul ignore next */
const returningProps = meta!.props.filter(prop => prop.primary || prop.defaultRaw);
const returningProps = meta!.hydrateProps.filter(prop => prop.primary || prop.defaultRaw);
const returningFields = Utils.flatten(returningProps.map(prop => prop.fieldNames));
/* istanbul ignore next */
sql += returningFields.length > 0 ? ` returning ${returningFields.map(field => this.platform.quoteIdentifier(field)).join(', ')}` : '';
Expand Down
2 changes: 1 addition & 1 deletion packages/knex/src/query/QueryBuilderHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export class QueryBuilderHelper {
const useReturningStatement = type === QueryType.INSERT && this.platform.usesReturningStatement() && meta && !meta.compositePK;

if (useReturningStatement) {
const returningProps = meta!.props.filter(prop => prop.primary || prop.defaultRaw);
const returningProps = meta!.hydrateProps.filter(prop => prop.primary || prop.defaultRaw);
qb.returning(Utils.flatten(returningProps.map(prop => prop.fieldNames)));
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/issues/GH1626.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export class Author {
@Property({ nullable: true })
name?: string;

@Property({ persist: false })
get nickname(): string {
return this.name ?? '~';
}

}

describe('GH issue 1626', () => {
Expand Down

0 comments on commit 35d51fe

Please sign in to comment.