Comments (4)
Some question
from typeorm-polymorphic.
I've managed to connect it with the latest version of @nestjs/typeorm (10.0.2) like this:
import { Injectable } from '@nestjs/common';
import { InjectDataSource } from '@nestjs/typeorm';
import { Organization} from './organization.entity';
import { DataSource } from 'typeorm';
import { AbstractPolymorphicRepository } from 'typeorm-polymorphic';
import { OrganizationRepository } from './organization.repository';
@Injectable()
export class OrganizationService {
private organizationRepository: OrganizationRepository;
constructor(
@InjectDataSource()
private dataSource: DataSource,
) {
this.organizationRepository = AbstractPolymorphicRepository.createRepository(
dataSource,
OrganizationRepository,
)
}
async getOrganizations(): Promise<Organization[]> {
return await this.organizationRepository.find();
}
}
OrganizationRepository
is the standard one from the README:
import { AbstractPolymorphicRepository, PolymorphicRepository } from 'typeorm-polymorphic';
import { Organization } from './organization.entity';
@PolymorphicRepository(Organization)
export class OrganizationRepository extends AbstractPolymorphicRepository<Organization> {}
from typeorm-polymorphic.
Hi.
Try something like this:
@Injectable()
export class MediumService {
constructor(
@InjectRepository(MediumEntity)
protected repository: AbstractPolymorphicRepository<MediumEntity>,
) {
this.repository = new class extends AbstractPolymorphicRepository<MediumEntity> {}(
this.repository.target, this.repository.manager
)
}
}
If you don't use the find methods from the repository (and instead use a builder or similar), you'll need to hydrate your response which will fill them with the necessary data, such as:
let response = await this.repository.createQueryBuilder().getMany()
response = await this.repository.hydrateMany(response);
from typeorm-polymorphic.
Hi.
Try something like this:
@Injectable() export class MediumService { constructor( @InjectRepository(MediumEntity) protected repository: AbstractPolymorphicRepository<MediumEntity>, ) { this.repository = new class extends AbstractPolymorphicRepository<MediumEntity> {}( this.repository.target, this.repository.manager ) } }If you don't use the find methods from the repository (and instead use a builder or similar), you'll need to hydrate your response which will fill them with the necessary data, such as:
let response = await this.repository.createQueryBuilder().getMany() response = await this.repository.hydrateMany(response);
How to insert data?
from typeorm-polymorphic.
Related Issues (20)
- [Question] Does this library support many-to-many polymorphic relation? HOT 3
- Possible bug: polymorphic entity creation not working HOT 1
- Relation with property path ** in entity was not found HOT 3
- Entity type is always null when eager loading HOT 1
- Entity does not have a primary column. HOT 1
- Polymorphic Inheritance HOT 1
- Massive refactor for clean up required HOT 2
- Subject is undefined when working with soft-deleted entities. HOT 1
- Polymorphic from parent not work HOT 3
- The implementation in the readme is wrong. HOT 3
- How to get children of parent
- Where is version 0.0.10? HOT 1
- Children not populated when retrieving parent
- Property "media" was not found in "User". Make sure your query is correct.
- EntityMetadataNotFoundError: No metadata for "null" was found
- How to generate migration?
- AbstractPolymorphicRepository.findPolymorphs uses wrong entityType HOT 2
- Update to work with newer TypeORM version HOT 1
- Creates N queries for hydrateMany HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm-polymorphic.