Skip to content

Commit 02b80da

Browse files
committed
feat: very important badges
1 parent 1b4ca71 commit 02b80da

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

README.md

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# typeorm-polymorphic
22
<a href="https://www.npmjs.com/package/typeorm-polymorphic"><img src="https://img.shields.io/npm/v/typeorm-polymorphic.svg"/></a>
3+
<a href="https://travis-ci.org/nestjsx/typeorm-paginate"><img src="https://travis-ci.org/nestjsx/typeorm-paginate.svg?branch=master"/></a>
4+
<img src="https://camo.githubusercontent.com/a34cfbf37ba6848362bf2bee0f3915c2e38b1cc1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5052732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265" />
35

46
An extension package for polymorphic relationship management, declaration and repository queries for [typeorm](https://typeorm.io/)
57

@@ -331,11 +333,10 @@ class UserEntity {
331333

332334
I think [Perf](https://github.com/Perf) might have some suggestions on how to improve things (sorry I have replied been mega busy!)
333335

334-
I've also used the class-transformer package so that my response objects have a different type value depending on the entityType. Could use the field tbh
335-
336336
## Nestjs
337337

338-
My methods work with basic hydration however the query builder needs some work. I've used a custom repository to handle all of the saving/updating/fetch. I only really use typeorm with nestjs hence I can use the repository anywhere in my project like so
338+
If you're using nestjs, don't forgot to include your repository into the entities array in forFeature
339+
339340
```ts
340341
@Module({
341342
imports: [
@@ -349,28 +350,3 @@ My methods work with basic hydration however the query builder needs some work.
349350
})
350351
export class AdvertModule {}
351352
```
352-
353-
Where `AdvertRepository` extends the `AbstractPolymorphicRepository`
354-
355-
```ts
356-
@EntityRepository(AdvertEntity)
357-
export class AdvertRepository extends AbstractPolymorphicRepository<
358-
AdvertEntity
359-
> {
360-
...
361-
```
362-
363-
Now whenever I call `advertRepository.findOne(1)` it'll also find the advert's parent (UserEntity | MerchantEntity).
364-
Same with saving
365-
366-
```ts
367-
advertRepository.save({
368-
owner: user,
369-
});
370-
```
371-
372-
Will automatically save the owner relationship. However this does depend on the user being an instanced UserEntity and not an object.
373-
374-
## Possible use case
375-
376-
It is possible to have multiple types for both parent + children however I've not tested this use case.

0 commit comments

Comments
 (0)