I am trying to develop a function to retrieve a user model based on a specific value within a OneToMany relationship.
Below is the function in question:
async getUserViaPlatform(provider: string, id: string) {
return await this.webUserRepository.findOne({
profiles: [{
provider,
platformID: id
}]
});
}
The structure of the User model is as follows:
@Entity()
export class WebUser {
@PrimaryGeneratedColumn()
id!: number;
@Column()
name!: string;
@Column({ nullable: true })
picture?: string;
@OneToMany(type => WebProfile, webProfile => webProfile.user, { eager: true })
profiles!: WebProfile[];
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
The "WebProfile" model looks like this:
@Entity()
export class WebProfile {
@PrimaryGeneratedColumn()
id!: number;
@Column()
provider!: string;
@Column()
email!: string;
@Column()
platformID!: string;
@ManyToOne(type => WebUser, user => user.profiles)
user!: WebUser;
@CreateDateColumn()
createdAt!: Date;
@UpdateDateColumn()
updatedAt!: Date;
}
My goal is to retrieve a user where a profile matches the provided provider and ID. However, currently, the function only returns the first user regardless of the input.