Feature(s) impacted
Hi, I have an entity called Asset
, which has. a one-to-one relation another Asset
, through the field thumbnail
and the FK thumbnailId
, using TypeORM it looks like this:
@Entity()
export class Asset {
@Column({ type: 'int', nullable: true })
thumbnailId: number | null
@OneToOne(() => Asset)
@JoinColumn({ name: 'thumbnailId' })
readonly thumbnail?: Asset | null
}
I have created the model for forest and added the association for the thumbnail
field with:
Asset.hasOne(models.asset, {
foreignKey: {
name: 'thumbnailId',
field: 'thumbnailId',
},
as: 'thumbnail',
})
Observed behavior
The problem is that when creating new thumbnail
from the Asset
parent on forest, it’s attaching automatically the thumbnailId
also to the child thumbnail (Asset), but I want that the association of thumbnailId
will be only on the parent Asset
only and not on the child Asset
(which is the thumbnail)
Parent Asset: {
id: 1,
thumbnailId: 10
}
Child Asset: {
id: 10,
thumbnailId: 1 // the association that happens on forest which I don't want
}
Expected behavior
When creating new child Asset
from a parent Asset
on one-to-one relation, the child Asset thumbnailId
should be null, only the thumbnailId
on the parent should have value
Parent Asset: {
id: 1,
thumbnailId: 10 // only parent entity need to have an association to the child Asset
}
Child Asset: {
id: 10,
thumbnailId: null
}
Context
- Agent (forest package) name & version: “forest-express-sequelize”: “^9.2.9”, “forest-cli”: “^4.1.3”, (nodejs )“engine_version”: “18.16.0”
- Database type: Postgres