Skip to content

Commit

Permalink
fix: bugfixes introduced in 0.3.0 (#8764)
Browse files Browse the repository at this point in the history
* fixes #8762; #8759; #8758; #8757;
  • Loading branch information
pleerock authored Mar 18, 2022
1 parent 941b584 commit d61f857
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 164 deletions.
2 changes: 1 addition & 1 deletion docs/custom-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In order to extend `UserRepository` functionality you can use `.extend` method o
```typescript
// user.repository.ts
export const UserRepository = dataSource.getRepository(User).extend({
findByName(firstName: string, lastName: string) {
findOneByName(firstName: string, lastName: string) {
return this.createQueryBuilder("user")
.where("user.firstName = :firstName", { firstName })
.andWhere("user.lastName = :lastName", { lastName })
Expand Down
11 changes: 0 additions & 11 deletions src/connection/options-reader/ConnectionOptionsEnvReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,6 @@ export class ConnectionOptionsEnvReader {
"TYPEORM_MAX_QUERY_EXECUTION_TIME",
),
debug: PlatformTools.getEnvVariable("TYPEORM_DEBUG"),
cli: {
entitiesDir: PlatformTools.getEnvVariable(
"TYPEORM_ENTITIES_DIR",
),
migrationsDir: PlatformTools.getEnvVariable(
"TYPEORM_MIGRATIONS_DIR",
),
subscribersDir: PlatformTools.getEnvVariable(
"TYPEORM_SUBSCRIBERS_DIR",
),
},
cache: this.transformCaching(),
uuidExtension: PlatformTools.getEnvVariable(
"TYPEORM_UUID_EXTENSION",
Expand Down
20 changes: 0 additions & 20 deletions src/data-source/BaseDataSourceOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,4 @@ export interface BaseDataSourceOptions {
*/
readonly ignoreErrors?: boolean
}

/**
* CLI settings.
*/
readonly cli?: {
/**
* Directory where entities should be created by default.
*/
readonly entitiesDir?: string

/**
* Directory where migrations should be created by default.
*/
readonly migrationsDir?: string

/**
* Directory where subscribers should be created by default.
*/
readonly subscribersDir?: string
}
}
22 changes: 8 additions & 14 deletions src/data-source/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,6 @@ export class DataSource {
*/
setOptions(options: Partial<DataSourceOptions>): this {
Object.assign(this.options, options)

this.logger = new LoggerFactory().create(
this.options.logger,
this.options.logging,
)
this.driver = new DriverFactory().create(this)
this.namingStrategy =
options.namingStrategy || new DefaultNamingStrategy()
this.queryResultCache = options.cache
? new QueryResultCacheFactory(this).create()
: undefined

// build all metadatas to make sure options are valid
// await this.buildMetadatas();
return this
}

Expand Down Expand Up @@ -681,5 +667,13 @@ export class DataSource {
),
this.driver,
)

// set current data source to the entities
for (let entityKey in flattenedEntities) {
const entity = flattenedEntities[entityKey]
if (InstanceChecker.isBaseEntityConstructor(entity)) {
entity.useDataSource(this)
}
}
}
}
9 changes: 8 additions & 1 deletion src/entity-manager/EntityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,14 @@ export class EntityManager {
withRepository<Entity, R extends Repository<Entity>>(repository: R): R {
const repositoryConstructor =
repository.constructor as typeof Repository
return new repositoryConstructor(repository.target, this) as R
const { target, manager, queryRunner, ...otherRepositoryProperties } =
repository
return Object.assign(
new repositoryConstructor(repository.target, this) as R,
{
...otherRepositoryProperties,
},
)
}

/**
Expand Down
Loading

0 comments on commit d61f857

Please sign in to comment.