Many-to-many relations with custom properties select
See original GitHub issueIssue type:
[x] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[x] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.x.x
(0.2.18)
Steps to reproduce or a small repository showing the problem:
Hi! I have many-to-many relations with custom properties. For example:
@Entity()
export default class Student {
@PrimaryGeneratedColumn()
id: number;
@Column()
firstName: string;
@Column()
lastName: string;
@Column()
age: number;
@OneToMany(() => StudentClassRoom, sc => sc.student)
studentClassRoom: StudentClassRoom[];
}
@Entity()
export default class ClassRoom {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
hasDesk: boolean;
@OneToMany(() => StudentClassRoom, sc => sc.classRoom)
studentClassRoom: StudentClassRoom[];
}
@Entity()
export default class StudentClassRoom {
@PrimaryGeneratedColumn()
id: number;
@ManyToOne(() => Student, student => student.studentClassRoom)
student: Student;
@ManyToOne(() => ClassRoom, classRoom => classRoom.studentClassRoom)
classRoom: ClassRoom;
}
How should my query look like to get something like this:
[
{
id: 1,
firstName: 'Jack',
age: 22,
classRoom: [
{
id:2,
name: 'History',
hasDesk: true
}
]
},
{
id: 2,
firstName: 'Kate',
age: 21,
classRoom: [
{
id:1,
name: 'Art',
hasDesk: false
},
{
id:3,
name: 'Math',
hasDesk: true
}
]
}
]
I have tried with left/inner join, map but to no avail( Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:26 (3 by maintainers)
Top Results From Across the Web
TypeORM: edit a many-to-many relations with custom properties
Im already using active record, and the relationship data is loaded with user entity find. · The query shows query: UPDATE 'user_roles' SET...
Read more >Many-to-many relations - typeorm - GitBook
Many-to-many is a relation where A contains multiple instances of B, and B contain multiple instances of A. Let's take for example Question...
Read more >How to create a custom many to many relationship in TypeORM
We will learn how to make this custom relationship using typeORM. Concepts. First of all let's review some concepts: The purpose of typeORM...
Read more >Many-to-many relations | TypeORM Docs
Many-to-many relations with custom properties. In case you need to have additional properties in your many-to-many relationship, you have to create a new...
Read more >Configuring how Relationship Joins
The objects will remain present in the collection until the attribute is expired and ... Many to many relationships can be customized by...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
any update on this?
Yes, I don’t get why the documentation shows you how to do it but doesn’t tell you how to make the query to get that relation when selecting. Would love to know how to do this properly.