I have two entity forms called 'Orders' and 'Address'. I want to embed Address form into orders form. Both entities are having relation by user column.
Address Entity
class Address
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=128)
*/
protected $type;
/**
* @ORM\ManyToOne(targetEntity="Root\UserBundle\Entity\User", inversedBy="address")
* @ORM\JoinColumn(name="user", referencedColumnName="id")
* @ORM\ManyToOne(targetEntity="Orders", inversedBy="address")
* @ORM\JoinColumn(name="user", referencedColumnName="user")
*/
protected $user;
Orders Entity
class Orders
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=128)
*/
protected $status;
/**
* @ORM\ManyToOne(targetEntity="Root\UserBundle\Entity\User", inversedBy="orders")
* @ORM\JoinColumn(name="user", referencedColumnName="id")
* @ORM\OneToMany(targetEntity="Address", mappedBy="orders")
* @ORM\JoinColumn(name="user", referencedColumnName="user")
*/
protected $user;
Orders Form
namespace Root\ContestBundle\Form\Front;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Root\ContestBundle\Entity\Address;
use Root\ContestBundle\Form\Front\AddressType;
class OrdersType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('address', 'collection', array('type' => new AddressType()));
$builder
->add('termsAccepted');
}
But I am getting error like below
An exception has been thrown during the rendering of a template ("Neither property "address" nor method "getAddress()" nor method "isAddress()" exists in class "Root\ContestBundle\Entity\Orders"")
So what mistake I have made in my code. Help me out
Maybe it's too late but here is my answer. I discovered symfony few days ago so I am no expert. There are few things that seems akward to me.
On Adress Entity, i think you should do that :
On Order Entity, I think you sould have that :
And last on you OrderType, I think you should have that :
Hope that will help you.