Relational Query Builder giving error when adding to many-to-many relationship
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] 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:
So I’ve been following the repository relations FAQ and other examples here, but it doesn’t seem to be working properly when trying to add an item to a many-to-many relationship
@Entity
class ContentItem
@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToMany(type => Image, image => image.contentItems)
images: Image[]
...
@Entity()
export class Image {
@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToMany(type => ContentItem, contentItem => contentItem.images)
@JoinTable()
contentItems: ContentItem[]
...
await getConnection()
.createQueryBuilder()
.relation(Image, "contentItems")
.of(imageId)
.add(contentItemId)
And the error response
code: "23502"
column: "image_id"
detail: "Failing row contains (null, null)."
file: "execMain.c"
length: 197
line: "2042"
message: "null value in column "image_id" violates not-null constraint"
name: "QueryFailedError"
parameters: []
query: "INSERT INTO "image_content_item"("image_id", "content_item_id") VALUES (DEFAULT, DEFAULT)"
routine: "ExecConstraints"
schema: "public"
severity: "ERROR"
stacktrace: ["QueryFailedError: null value in column "image_id" violates not-null constraint",…]
table: "image_content_item"
For some reason it’s not binding the parameters so the insert fails
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Query builder ManyToMany relationship - Stack Overflow
It doesn't work and give me the error: Invalid PathExpression. StateFieldPathExpression or SingleValuedAssociationField expected. symfony ...
Read more >Many-to-one / one-to-many relations - typeorm - GitBook
Many-to-one / one-to-many is a relation where A contains multiple instances of B, but B contains only one instance of A. Let's take...
Read more >Object Relational Tutorial (1.x API)
A second directive, known as relationship() , tells the ORM that the Address class itself should be linked to the User class, using...
Read more >Hibernate ORM 5.4.33.Final User Guide - Red Hat on GitHub
Querying for entities using entity relation joins; 21.17. ... toLongArray() ) { if ( builder.length() > 0 ) { builder.append( DELIMITER ); }...
Read more >Eloquent: Relationships - The PHP Framework For Web Artisans
A one-to-one relationship is a very basic relation. ... Of course, since all relationships also serve as query builders, you can add further...
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 FreeTop 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
Top GitHub Comments
I have this exact issue too.
I think it’s similar to #2612 and #3320