-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.5 (or put your version here)
Steps to reproduce or a small repository showing the problem:
I have a table named difficulties which have two fields: an id field (primary, auto-generated) and a type varchar field.
I'm running the following insert:
return connection.manager.insert('difficulties', [
{ type: 'Easy' },
{ type: 'Medium' },
{ type: 'Hard' },
]);
To my surprise, this query was generated:
The result is unexpected to me because I specified that I wanted to insert the type column, but Typeorm didn't specify that in the query.
Digging down through the code I found out this function, which appears to be the one where the issue is:
| protected createColumnNamesExpression(): string { |
// <some code>.
// in the case if there are no insert columns specified and table without metadata used
// we get columns from the inserted value map, in the case if only one inserted map is specified
if (!this.expressionMap.mainAlias!.hasMetadata && !this.expressionMap.insertColumns.length) {
const valueSets = this.getValueSets();
if (valueSets.length === 1)
return Object.keys(valueSets[0]).map(columnName => this.escape(columnName)).join(", ");
}
// <some code>.
if I remove the check if (valueSets.length === 1), Typeorm generates the correct query and the information is inserted successfully:
My questions would be:
-
Am I using the entity manager the wrong way? If so, how do I specify the columns that I want to insert into a table passing the table's name as a string?
-
I don't have enough context about the code or understand the comment that was left to be able to make a PR removing it - perhaps it's fixing something that I'm not aware of. In that case, should we come up with a better solution, other than removing the check
if (valueSets.length === 1)?

