Skip to content

Commit 3cac4ba

Browse files
docs(entity-schemas): small tweaks
1 parent 181eb01 commit 3cac4ba

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

content/techniques/sql.md

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -358,46 +358,45 @@ With that option specified, every entity registered through the `forFeature()` m
358358

359359
> warning **Warning** Note that entities that aren't registered through the `forFeature()` method, but are only referenced from the entity (via a relationship), won't be included by way of the `autoLoadEntities` setting.
360360
361-
#### Separating Entity Definition
362-
363-
You can define an entity and its columns right in the model, using decorators. But some people prefer to define an entity and its columns inside separate files which are called ["entity schemas"](https://typeorm.io/#/separating-entity-definition).
361+
#### Separating entity definition
364362

363+
You can define an entity and its columns right in the model, using decorators. But some people prefer to define entities and their columns inside separate files using the ["entity schemas"](https://typeorm.io/#/separating-entity-definition).
365364

366365
```typescript
367366
import { EntitySchema } from 'typeorm';
368367
import { User } from './user.entity';
369368

370369
export const UserSchema = new EntitySchema<User>({
371-
name: 'User',
372-
target: User,
373-
columns: {
374-
id: {
375-
type: Number,
376-
primary: true,
377-
generated: true
378-
},
379-
firstName: {
380-
type: String
381-
},
382-
lastName: {
383-
type: String
384-
},
385-
isActive: {
386-
type: Boolean,
387-
default: true
388-
}
370+
name: 'User',
371+
target: User,
372+
columns: {
373+
id: {
374+
type: Number,
375+
primary: true,
376+
generated: true,
377+
},
378+
firstName: {
379+
type: String,
380+
},
381+
lastName: {
382+
type: String,
383+
},
384+
isActive: {
385+
type: Boolean,
386+
default: true,
389387
},
390-
relations: {
391-
photos: {
392-
type: 'one-to-many',
393-
target: 'Photo' // The name of the PhotoSchema
394-
}
395-
}
388+
},
389+
relations: {
390+
photos: {
391+
type: 'one-to-many',
392+
target: 'Photo', // the name of the PhotoSchema
393+
},
394+
},
396395
});
397396
```
398-
> error **Warning** If you provide the `target` option, the `name` option value has to be the same as the name of the target class.
399-
> If you do not provide the `target` you can use any name.
400397

398+
> warning error **Warning** If you provide the `target` option, the `name` option value has to be the same as the name of the target class.
399+
> If you do not provide the `target` you can use any name.
401400
402401
Nest allows you to use an `EntitySchema` instance wherever an `Entity` is expected, for example:
403402

0 commit comments

Comments
 (0)