mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fixes #78
This commit is contained in:
parent
102856540c
commit
044e215bfd
@ -25,13 +25,14 @@ export class PlainObjectToNewEntityTransformer {
|
||||
* we need to group our result and we must have some unique id (primary key in our case)
|
||||
*/
|
||||
private groupAndTransform(entity: any, object: ObjectLiteral, metadata: EntityMetadata): void {
|
||||
|
||||
// copy regular column properties from the given object
|
||||
metadata.columns
|
||||
metadata.allColumns
|
||||
.filter(column => object.hasOwnProperty(column.propertyName))
|
||||
.forEach(column => entity[column.propertyName] = object[column.propertyName]); // todo: also need to be sure that type is correct
|
||||
|
||||
// if relation is loaded then go into it recursively and transform its values too
|
||||
metadata.relations
|
||||
metadata.allRelations
|
||||
.filter(relation => object.hasOwnProperty(relation.propertyName))
|
||||
.forEach(relation => {
|
||||
const relationMetadata = relation.inverseEntityMetadata;
|
||||
|
||||
11
test/issues/78/entity/DeliveryNote.ts
Normal file
11
test/issues/78/entity/DeliveryNote.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {Document} from "./Document";
|
||||
import {ClassTableChild} from "../../../../src/decorator/tables/ClassTableChild";
|
||||
|
||||
@ClassTableChild()
|
||||
export class DeliveryNote extends Document {
|
||||
|
||||
@Column()
|
||||
invoice: string = "";
|
||||
|
||||
}
|
||||
42
test/issues/78/entity/Document.ts
Normal file
42
test/issues/78/entity/Document.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import {Table} from "../../../../src/decorator/tables/Table";
|
||||
import {PrimaryGeneratedColumn} from "../../../../src/decorator/columns/PrimaryGeneratedColumn";
|
||||
import {Column} from "../../../../src/decorator/columns/Column";
|
||||
import {TableInheritance} from "../../../../src/decorator/tables/TableInheritance";
|
||||
import {CreateDateColumn} from "../../../../src/decorator/columns/CreateDateColumn";
|
||||
import {UpdateDateColumn} from "../../../../src/decorator/columns/UpdateDateColumn";
|
||||
|
||||
@Table()
|
||||
@TableInheritance("class-table")
|
||||
export class Document {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
dollarRate: number = 0;
|
||||
|
||||
@Column()
|
||||
orderBy: string = "";
|
||||
|
||||
@Column()
|
||||
comments: string = "";
|
||||
|
||||
@Column()
|
||||
subTotal: number = 0;
|
||||
|
||||
@Column()
|
||||
vat: number = 0;
|
||||
|
||||
@Column()
|
||||
total: number = 0;
|
||||
|
||||
@Column()
|
||||
createdBy: string = "";
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: string;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: string;
|
||||
|
||||
}
|
||||
48
test/issues/78/issue-78.ts
Normal file
48
test/issues/78/issue-78.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import "reflect-metadata";
|
||||
import {setupTestingConnections, closeConnections, reloadDatabases} from "../../utils/test-utils";
|
||||
import {Connection} from "../../../src/connection/Connection";
|
||||
import {DeliveryNote} from "./entity/DeliveryNote";
|
||||
import {expect} from "chai";
|
||||
|
||||
describe("github issues > #78 repository 'create' is skipping inherited fields", () => {
|
||||
|
||||
let connections: Connection[];
|
||||
before(async () => connections = await setupTestingConnections({
|
||||
entities: [__dirname + "/entity/*{.js,.ts}"],
|
||||
schemaCreate: true,
|
||||
}));
|
||||
beforeEach(() => reloadDatabases(connections));
|
||||
after(() => closeConnections(connections));
|
||||
|
||||
it("should persist successfully and return persisted entity", () => Promise.all(connections.map(async connection => {
|
||||
const repository = connection.getRepository(DeliveryNote);
|
||||
|
||||
const deliveryNoteEntity = repository.create({
|
||||
id: 1,
|
||||
dollarRate: 0.5,
|
||||
orderBy: "money",
|
||||
comments: "this is comment",
|
||||
subTotal: 10,
|
||||
vat: 50,
|
||||
total: 60,
|
||||
createdBy: "Amir",
|
||||
invoice: "Total Invoice: 60"
|
||||
});
|
||||
|
||||
expect(deliveryNoteEntity).not.to.be.empty;
|
||||
deliveryNoteEntity.should.be.instanceof(DeliveryNote);
|
||||
deliveryNoteEntity.should.be.eql({
|
||||
id: 1,
|
||||
dollarRate: 0.5,
|
||||
orderBy: "money",
|
||||
comments: "this is comment",
|
||||
subTotal: 10,
|
||||
vat: 50,
|
||||
total: 60,
|
||||
createdBy: "Amir",
|
||||
invoice: "Total Invoice: 60"
|
||||
});
|
||||
|
||||
})));
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user