This commit is contained in:
Umed Khudoiberdiev 2017-07-27 17:52:51 +05:00
parent f536c1144d
commit f2d958ebf7
4 changed files with 48 additions and 2 deletions

View File

@ -88,7 +88,7 @@ This code will log all queries which run more then `1 second`.
There are several loggers TypeORM ships with 3 different types of loggers:
* `advanced-console` - this is default logger which logs all messages into console using color
and sql syntax highlighting (using [chalk]() package)
and sql syntax highlighting (using [chalk](https://github.com/chalk/chalk) package)
* `simple-console` - this is simple console logger which is exactly the same as advanced, but it does not use any color highlighting.
This logger can be used if you have problems / or don't like colorized logs
* `file` - this logger writes all logs into `ormlogs.log` file in the root folder of your project (near `package.json` and `ormconfig.json`)

View File

@ -161,7 +161,11 @@ export class DateUtils {
*/
static stringToSimpleArray(value: string|any): string|any {
if (value instanceof String || typeof value === "string") {
return value.split(",");
if (value.length > 0) {
return value.split(",");
} else {
return [];
}
}
return value;

View File

@ -0,0 +1,14 @@
import {Entity} from "../../../../src/decorator/entity/Entity";
import {PrimaryColumn} from "../../../../src/decorator/columns/PrimaryColumn";
import {Column} from "../../../../src/decorator/columns/Column";
@Entity()
export class Post {
@PrimaryColumn()
id: number;
@Column("simple-array")
names: string[];
}

View File

@ -0,0 +1,28 @@
import "reflect-metadata";
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
import {Connection} from "../../../src/connection/Connection";
import {Post} from "./entity/Post";
describe.only("github issues > #463 saving empty string array", () => {
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
enabledDrivers: ["postgres"],
schemaCreate: true,
dropSchemaOnConnection: true,
}));
beforeEach(() => reloadTestingDatabases(connections));
after(() => closeTestingConnections(connections));
it("should not return array with single empty string if empty array was saved", () => Promise.all(connections.map(async connection => {
const post = new Post();
post.id = 1;
post.names = [];
await connection.getRepository(Post).persist(post);
const loadedPost = await connection.getRepository(Post).findOneById(1);
console.log(loadedPost);
loadedPost!.names.length.should.be.eql(0);
})));
});