mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixed issue with joined empty relations inside empty objects
This commit is contained in:
parent
bcef8953cf
commit
14b67da103
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "typeorm",
|
||||
"private": true,
|
||||
"version": "0.0.7-alpha.22",
|
||||
"version": "0.0.7-alpha.23",
|
||||
"description": "Data-Mapper ORM for TypeScript, ES7, ES6, ES5. Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, WebSQL databases.",
|
||||
"license": "MIT",
|
||||
"readmeFilename": "README.md",
|
||||
|
||||
@ -156,7 +156,9 @@ export class RawSqlResultsToEntityTransformer {
|
||||
} else {
|
||||
entity[propertyName] = result;
|
||||
}
|
||||
hasData = true;
|
||||
|
||||
if (!isResultArray || result.length > 0)
|
||||
hasData = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
test/other-issues/join-empty-relations/entity/Author.ts
Normal file
14
test/other-issues/join-empty-relations/entity/Author.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import {Entity} from "../../../../src/decorator/entity/Entity";
|
||||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
|
||||
@Entity()
|
||||
export class Author {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
}
|
||||
21
test/other-issues/join-empty-relations/entity/Category.ts
Normal file
21
test/other-issues/join-empty-relations/entity/Category.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import {Entity} from "../../../../src/decorator/entity/Entity";
|
||||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {JoinTable} from "../../../../src/decorator/relations/JoinTable";
|
||||
import {ManyToMany} from "../../../../src/decorator/relations/ManyToMany";
|
||||
import {Author} from "./Author";
|
||||
|
||||
@Entity()
|
||||
export class Category {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@ManyToMany(type => Author)
|
||||
@JoinTable()
|
||||
authors: Author[];
|
||||
|
||||
}
|
||||
21
test/other-issues/join-empty-relations/entity/Post.ts
Normal file
21
test/other-issues/join-empty-relations/entity/Post.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import {Entity} from "../../../../src/decorator/entity/Entity";
|
||||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {Category} from "./Category";
|
||||
import {ManyToMany} from "../../../../src/decorator/relations/ManyToMany";
|
||||
import {JoinTable} from "../../../../src/decorator/relations/JoinTable";
|
||||
|
||||
@Entity()
|
||||
export class Post {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
title: string;
|
||||
|
||||
@ManyToMany(type => Category)
|
||||
@JoinTable()
|
||||
categories: Category[];
|
||||
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
import "reflect-metadata";
|
||||
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils";
|
||||
import {Connection} from "../../../src/connection/Connection";
|
||||
import {Post} from "./entity/Post";
|
||||
import {expect} from "chai";
|
||||
|
||||
describe.only("other issues > joining empty relations", () => {
|
||||
|
||||
let connections: Connection[];
|
||||
before(async () => connections = await createTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
schemaCreate: true,
|
||||
dropSchemaOnConnection: true,
|
||||
}));
|
||||
beforeEach(() => reloadTestingDatabases(connections));
|
||||
after(() => closeTestingConnections(connections));
|
||||
|
||||
it("should return empty array if its joined and nothing was found", () => Promise.all(connections.map(async function(connection) {
|
||||
|
||||
const post = new Post();
|
||||
post.title = "Hello Post";
|
||||
await connection.entityManager.persist(post);
|
||||
|
||||
// check if ordering by main object works correctly
|
||||
|
||||
const loadedPosts1 = await connection.entityManager
|
||||
.createQueryBuilder(Post, "post")
|
||||
.leftJoinAndSelect("post.categories", "categories")
|
||||
.getMany();
|
||||
|
||||
expect(loadedPosts1).not.to.be.empty;
|
||||
loadedPosts1.should.be.eql([{
|
||||
id: 1,
|
||||
title: "Hello Post",
|
||||
categories: []
|
||||
}]);
|
||||
|
||||
})));
|
||||
|
||||
it("should return empty array if its joined and nothing was found, but relations in empty results should be skipped", () => Promise.all(connections.map(async function(connection) {
|
||||
|
||||
const post = new Post();
|
||||
post.title = "Hello Post";
|
||||
await connection.entityManager.persist(post);
|
||||
|
||||
// check if ordering by main object works correctly
|
||||
|
||||
const loadedPosts1 = await connection.entityManager
|
||||
.createQueryBuilder(Post, "post")
|
||||
.leftJoinAndSelect("post.categories", "categories")
|
||||
.leftJoinAndSelect("categories.authors", "authors")
|
||||
.getMany();
|
||||
|
||||
expect(loadedPosts1).not.to.be.empty;
|
||||
loadedPosts1.should.be.eql([{
|
||||
id: 1,
|
||||
title: "Hello Post",
|
||||
categories: []
|
||||
}]);
|
||||
|
||||
})));
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user