mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
bugfixes
This commit is contained in:
parent
43d90f4a0b
commit
f649ff98f2
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "typeorm",
|
||||
"private": true,
|
||||
"version": "0.0.2-alpha.17",
|
||||
"version": "0.0.2-alpha.18",
|
||||
"description": "Data-mapper ORM for Typescript",
|
||||
"license": "Apache-2.0",
|
||||
"readmeFilename": "README.md",
|
||||
|
||||
@ -71,9 +71,9 @@ export class EntityPersistOperationBuilder {
|
||||
persistOperation.allDbEntities = dbEntities;
|
||||
persistOperation.allPersistedEntities = allPersistedEntities;
|
||||
persistOperation.inserts = this.findCascadeInsertedEntities(persistedEntity, dbEntities);
|
||||
persistOperation.updates = this.findCascadeUpdateEntities(metadata, dbEntity, persistedEntity);
|
||||
persistOperation.junctionInserts = this.findJunctionInsertOperations(metadata, persistedEntity, dbEntities);
|
||||
persistOperation.updatesByRelations = this.updateRelations(persistOperation.inserts, persistedEntity);
|
||||
persistOperation.updates = this.findCascadeUpdateEntities(persistOperation.updatesByRelations, metadata, dbEntity, persistedEntity);
|
||||
persistOperation.junctionInserts = this.findJunctionInsertOperations(metadata, persistedEntity, dbEntities);
|
||||
persistOperation.removes = this.findCascadeRemovedEntities(metadata, dbEntity, allPersistedEntities, undefined, undefined, undefined);
|
||||
persistOperation.junctionRemoves = this.findJunctionRemoveOperations(metadata, dbEntity, allPersistedEntities);
|
||||
return persistOperation;
|
||||
@ -135,7 +135,8 @@ export class EntityPersistOperationBuilder {
|
||||
return operations;
|
||||
}
|
||||
|
||||
private findCascadeUpdateEntities(metadata: EntityMetadata,
|
||||
private findCascadeUpdateEntities(updatesByRelations: UpdateByRelationOperation[],
|
||||
metadata: EntityMetadata,
|
||||
dbEntity: any,
|
||||
newEntity: any,
|
||||
fromRelation?: RelationMetadata,
|
||||
@ -144,7 +145,7 @@ export class EntityPersistOperationBuilder {
|
||||
return operations;
|
||||
|
||||
const diffColumns = this.diffColumns(metadata, newEntity, dbEntity);
|
||||
const diffRelations = this.diffRelations(metadata, newEntity, dbEntity);
|
||||
const diffRelations = this.diffRelations(updatesByRelations, metadata, newEntity, dbEntity);
|
||||
if (diffColumns.length && fromRelation && !this.checkCascadesAllowed("update", metadata, fromRelation)) {
|
||||
return operations;
|
||||
|
||||
@ -168,11 +169,11 @@ export class EntityPersistOperationBuilder {
|
||||
const subDbEntity = dbValue.find((subDbEntity: any) => {
|
||||
return subDbEntity[relationIdColumnName] === subEntity[relationIdColumnName];
|
||||
});
|
||||
this.findCascadeUpdateEntities(relMetadata, subDbEntity, subEntity, relation, operations);
|
||||
this.findCascadeUpdateEntities(updatesByRelations, relMetadata, subDbEntity, subEntity, relation, operations);
|
||||
});
|
||||
|
||||
} else {
|
||||
this.findCascadeUpdateEntities(relMetadata, dbValue, value, relation, operations);
|
||||
this.findCascadeUpdateEntities(updatesByRelations, relMetadata, dbValue, value, relation, operations);
|
||||
}
|
||||
});
|
||||
|
||||
@ -346,9 +347,10 @@ export class EntityPersistOperationBuilder {
|
||||
.filter(column => newEntity[column.propertyName] !== dbEntity[column.name]);
|
||||
}
|
||||
|
||||
private diffRelations(metadata: EntityMetadata, newEntity: any, dbEntity: any) {
|
||||
private diffRelations(updatesByRelations: UpdateByRelationOperation[], metadata: EntityMetadata, newEntity: any, dbEntity: any) {
|
||||
return metadata.relations
|
||||
.filter(relation => relation.isManyToOne || (relation.isOneToOne && relation.isOwning))
|
||||
.filter(relation => !updatesByRelations.find(operation => operation.targetEntity === newEntity && operation.updatedRelation === relation)) // try to find if there is update by relation operation - we dont need to generate update relation operation for this
|
||||
.filter(relation => newEntity[relation.propertyName] !== dbEntity[relation.name]);
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,9 @@ export interface Join {
|
||||
isMappingMany: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export interface JoinMapping {
|
||||
alias: Alias;
|
||||
parentName: string;
|
||||
@ -416,7 +419,7 @@ export class QueryBuilder<Entity> {
|
||||
]);
|
||||
}
|
||||
|
||||
clone(options?: { skipOrderBys?: boolean }) {
|
||||
clone(options?: { skipOrderBys?: boolean, skipLimit?: boolean, skipOffset?: boolean }) {
|
||||
const qb = new QueryBuilder(this.driver, this.entityMetadatas, this.broadcaster);
|
||||
|
||||
switch (this.type) {
|
||||
@ -477,9 +480,13 @@ export class QueryBuilder<Entity> {
|
||||
|
||||
Object.keys(this.parameters).forEach(key => qb.setParameter(key, this.parameters[key]));
|
||||
|
||||
qb.setLimit(this.limit)
|
||||
.setOffset(this.offset)
|
||||
.setFirstResult(this.firstResult)
|
||||
if (!options || !options.skipLimit)
|
||||
qb.setLimit(this.limit);
|
||||
|
||||
if (!options || !options.skipOffset)
|
||||
qb.setOffset(this.offset);
|
||||
|
||||
qb.setFirstResult(this.firstResult)
|
||||
.setMaxResults(this.maxResults);
|
||||
|
||||
return qb;
|
||||
@ -536,8 +543,12 @@ export class QueryBuilder<Entity> {
|
||||
|
||||
let alias: string = "", tableName: string;
|
||||
const allSelects: string[] = [];
|
||||
|
||||
if (this.fromEntity) {
|
||||
|
||||
if (this.fromTableName) {
|
||||
tableName = this.fromTableName;
|
||||
alias = this.fromTableAlias;
|
||||
|
||||
} else if (this.fromEntity) {
|
||||
const metadata = this.aliasMap.getEntityMetadataByAlias(this.fromEntity.alias);
|
||||
tableName = metadata.table.name;
|
||||
alias = this.fromEntity.alias.name;
|
||||
@ -548,10 +559,7 @@ export class QueryBuilder<Entity> {
|
||||
allSelects.push(alias + "." + column.name + " AS " + alias + "_" + column.name);
|
||||
});
|
||||
}
|
||||
|
||||
} else if (this.fromTableName) {
|
||||
tableName = this.fromTableName;
|
||||
|
||||
|
||||
} else {
|
||||
throw new Error("No from given");
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
/**
|
||||
* Loads all exported classes from the given directory.
|
||||
@ -7,7 +8,6 @@ import * as fs from "fs";
|
||||
export class DirectoryExportedClassesLoader {
|
||||
|
||||
// todo: this can be extracted into external module and used across all other modules
|
||||
// todo: add support for glob patterns
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
@ -17,9 +17,14 @@ export class DirectoryExportedClassesLoader {
|
||||
* Imports all entities (makes them "require") from the given directories.
|
||||
*/
|
||||
importClassesFromDirectories(directories: string[]): Function[] {
|
||||
|
||||
const allDirectories = directories.reduce((allDirs, dir) => {
|
||||
return allDirs.concat(require("glob").sync(path.normalize(dir)));
|
||||
}, [] as string[]);
|
||||
|
||||
const requireAll = require("require-all");
|
||||
const filter = /(.*)\.js$/;
|
||||
const dirs = directories
|
||||
const dirs = allDirectories
|
||||
.filter(directory => fs.existsSync(directory))
|
||||
.map(directory => requireAll({ dirname: directory, filter: filter, recursive: true }));
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import "reflect-metadata";
|
||||
import * as chai from "chai";
|
||||
import {expect} from "chai";
|
||||
import {Connection} from "../../src/connection/Connection";
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import "reflect-metadata";
|
||||
import * as chai from "chai";
|
||||
import {expect} from "chai";
|
||||
import {Connection} from "../../src/connection/Connection";
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import "reflect-metadata";
|
||||
import * as chai from "chai";
|
||||
import {expect} from "chai";
|
||||
import {Connection} from "../../src/connection/Connection";
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import "reflect-metadata";
|
||||
import * as chai from "chai";
|
||||
import {expect} from "chai";
|
||||
import {Connection} from "../../src/connection/Connection";
|
||||
import {CreateConnectionOptions, createConnection} from "../../src/typeorm";
|
||||
import {Repository} from "../../src/repository/Repository";
|
||||
import {SchemaCreator} from "../../src/schema-creator/SchemaCreator";
|
||||
import {PostDetails} from "../../sample/sample4-many-to-many/entity/PostDetails";
|
||||
import {Post} from "../../sample/sample4-many-to-many/entity/Post";
|
||||
import {PostCategory} from "../../sample/sample4-many-to-many/entity/PostCategory";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user