You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[x] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
I'm terribly tired so apologies if the answer is obvious, and I'm just blind and not seeing it.
Assuming the following two entities:
@Entity()exportclassParent{
@PrimaryGeneratedColumn()id!: number
@OneToMany(type=>Child,child=>child.parent)children!: Child[]}
@Entity()exportclassChild{
@PrimaryGeneratedColumn()id!: number
@ManyToOne(type=>Parent,parent=>parent.children,{nullable: false})parent!: Parent}
When doing entityManager.insert(Child, {}), naturally the error null value in column \"parentId\" violates not-null constraint is thrown. When trying to do entityManager.insert(Child, { parentId: 1 }), the same error is thrown though.
So how do I create and save new Childs with the above model?
The text was updated successfully, but these errors were encountered:
Your Child entity do not have defined parentId column in entity class. I am getting error in IDE
Object literal may only specify known properties, and 'parentId' does not exist in type 'QueryPartialEntity<Child> | QueryPartialEntity<Child>[]'. [2345]
So typeorm will ignore this property value during query build. Of course typeorm know about this join column but entity argument of insert is QueryPartialEntity<Child>|(QueryPartialEntity<Child>[]) so does not expect parentId property.
Issue type:
[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[x]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[x]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
I'm terribly tired so apologies if the answer is obvious, and I'm just blind and not seeing it.
Assuming the following two entities:
When doing
entityManager.insert(Child, {})
, naturally the errornull value in column \"parentId\" violates not-null constraint
is thrown. When trying to doentityManager.insert(Child, { parentId: 1 })
, the same error is thrown though.So how do I create and save new
Child
s with the above model?The text was updated successfully, but these errors were encountered: