guys!)
I have 2 entity.
position.entity
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
import { User } from '../../user/entities/user.entity';
@Entity()
export class Position {
@PrimaryGeneratedColumn()
id: number;
@OneToMany(() => User, (user) => user.position)
users: User[];
@Column()
name: string;
}
user.entity
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
import { Position } from '../../positions/entities/position.entity';
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
email: string;
@Column()
phone: string;
@Column()
position_id: number;
@Column()
photo: string;
@ManyToOne(() => Position, (position) => position.users)
@JoinColumn({ name: 'position' })
position: Position;
@CreateDateColumn()
registration_timestamp: string;
}
data in table ‘position’
id name
1 Security
2 Designer
3 Lawyer
when I registration user I’m transmitting this data
{
"name":"Vanya",
"email": "[email protected]",
"phone": "+380931133323",
"position_id": 2,
"photo": "ssss"
}
When I output a list of users, I have NULL in user.position. And I have NULL in the ‘position’ column of the ‘User’ table. And I need to have the user’s position pulled up to me when I output the user. I suspect I’m doing something wrong when writing a user to the database, but I can’t figure out what.I’m just learning. Guys, what am I doing wrong?