Skip to content

Commit

Permalink
Merge pull request #1 from kingcody/0.2.7-x
Browse files Browse the repository at this point in the history
Fallback to maybeOptions for findOne
  • Loading branch information
wujunyucg committed Sep 17, 2018
2 parents 501d826 + 00e45e0 commit 6a5eb44
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,5 +1,5 @@
<div align="center">
<a href="https://typeorm.io/">
<a href="http://typeorm.io/">
<img src="https://github.com/typeorm/typeorm/raw/master/resources/logo_big.png" width="492" height="228">
</a>
<br>
Expand Down
1 change: 1 addition & 0 deletions docs/one-to-one-relations.md
Expand Up @@ -77,6 +77,7 @@ profile.photo = "me.jpg";
await connection.manager.save(profile);

const user = new User();
user.name = 'Joe Smith';
user.profile = profile;
await connection.manager.save(user);
```
Expand Down
2 changes: 1 addition & 1 deletion docs/supported-platforms.md
Expand Up @@ -63,7 +63,7 @@ TypeORM is able to on React Native apps using the [react-native-sqlite-storage](

## Expo

TypeORM is able to run on Expo apps using the [Expo SQLite API](https://docs.expo.io/versions/latest/sdk/sqlite.html).
TypeORM is able to run on Expo apps using the [Expo SQLite API](https://docs.expo.io/versions/latest/sdk/sqlite.html). For an example how to use TypeORM in Expo see [typeorm/react-native-example](https://github.com/typeorm/react-native-example).

## NativeScript

Expand Down
15 changes: 8 additions & 7 deletions src/entity-manager/MongoEntityManager.ts
Expand Up @@ -165,16 +165,17 @@ export class MongoEntityManager extends EntityManager {
maybeOptions?: FindOneOptions<Entity>): Promise<Entity|undefined> {
const objectIdInstance = PlatformTools.load("mongodb").ObjectID;
const id = (optionsOrConditions instanceof objectIdInstance) || typeof optionsOrConditions === "string" ? optionsOrConditions : undefined;
const query = this.convertFindOneOptionsOrConditionsToMongodbQuery((id ? maybeOptions : optionsOrConditions) as any) || {};
const findOneOptionsOrConditions = (id ? maybeOptions : optionsOrConditions) as any;
const query = this.convertFindOneOptionsOrConditionsToMongodbQuery(findOneOptionsOrConditions) || {};
if (id) {
query["_id"] = (id instanceof objectIdInstance) ? id : new objectIdInstance(id);
}
const cursor = await this.createEntityCursor(entityClassOrName, query);
if (FindOptionsUtils.isFindOneOptions(optionsOrConditions)) {
if (optionsOrConditions.select)
cursor.project(this.convertFindOptionsSelectToProjectCriteria(optionsOrConditions.select));
if (optionsOrConditions.order)
cursor.sort(this.convertFindOptionsOrderToOrderCriteria(optionsOrConditions.order));
if (FindOptionsUtils.isFindOneOptions(findOneOptionsOrConditions)) {
if (findOneOptionsOrConditions.select)
cursor.project(this.convertFindOptionsSelectToProjectCriteria(findOneOptionsOrConditions.select));
if (findOneOptionsOrConditions.order)
cursor.sort(this.convertFindOptionsOrderToOrderCriteria(findOneOptionsOrConditions.order));
}

// const result = await cursor.limit(1).next();
Expand Down Expand Up @@ -680,4 +681,4 @@ export class MongoEntityManager extends EntityManager {
};
}

}
}

0 comments on commit 6a5eb44

Please sign in to comment.