Reputation: 1
I've got a simple blog form with a many-to-many relation for the blogCategories. If i save it, before i call persist, the blog object has the blogCategories, but flush won't create the entries in the n:m table.
I have no error at all.
But if i call $blog->addBlogCategory($blogCategory) with a blogCategory object, it saves perfectly, which leads me to the conclusion that the relation is properly configured.
When i add a blogCategory explicitly, the object looks like this, where the first three are added by form and the last added explicitly:
App\Entity\BlogEntry {#628 ▼
-id: null
-name: "65730a3121b23"
-headline: "test"
-content: "<p>stack overflow</p>"
-published: true
-preview_picture: null
-releaseTime: DateTimeImmutable @1702038065 {#1255 ▶}
-blogCategories: Doctrine\Common\Collections\ArrayCollection {#629 ▼
-elements: array:4 [▼
0 => App\Entity\BlogCategory {#1269 ▼
-id: 2
-name: "1869478cc6"
-ident: "Betriebsrat"
-blogEntry: Doctrine\ORM\PersistentCollection {#1276 ▶}
}
1 => App\Entity\BlogCategory {#1273 ▼
-id: 3
-name: "017623d368"
-ident: "Gut drauf"
-blogEntry: Doctrine\ORM\PersistentCollection {#1272 ▶}
}
2 => App\Entity\BlogCategory {#1270 ▼
-id: 4
-name: "13afe00644"
-ident: "Heimbeirat"
-blogEntry: Doctrine\ORM\PersistentCollection {#1294 ▶}
}
3 => App\Entity\BlogCategory {#1304 ▼
-id: 5
-name: "0635ff2d31"
-ident: "IT"
-blogEntry: Doctrine\ORM\PersistentCollection {#1371 ▶}
}
]
}
-author: Proxies\__CG__\App\Entity\Employee {#472 ▶}
}
EDIT: SOLVED as Marleen mentioned, the field had to be by_reference=false, then it works great.
Upvotes: 0
Views: 43