Symfony form collection
It's not clear what your mapping is between your Customer
entity and your Profile
entity, but I guess there are 2 options:
Option 1: You have a OneToOne relationship (One customer can only have One profile). Therefore, you don't need the collection at all but simply need to embed a single object.
->add('profile', new ProfileType());
Option 2: You want a ManyToOne relationship (One customer can have many profiles). In that case, you need to use to embed a collection of forms. If this is what you want, rename $profile
to $profiles
in your Customer entity, and do the following:
//MV\CMSBundle\Entity\Customer use Doctrine\Common\Collections\ArrayCollection; /** * Your mapping here. * * @ORM\ManyToOne(targetEntity="MV\NameBundle\Entity\Profile") */ protected $profiles; public function __construct() { //This is why you had an error, this is missing from your entity //An object was sent instead of a collection. $this->profiles = new ArrayCollection(); }
Finally, update your database.