I'm building a form generator using Symfony 2.2 with Doctrine.
My entities are the following:
- Form
- WidgetText
- WidgetSelect
All my widgets extend the following class:
/**
* Widget
*
* @ORM\MappedSuperclass
*/
abstract class Widget
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Form", inversedBy="widgets")
*/
private $form;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255)
*/
private $type;
/**
* @var integer
*
* @ORM\OneToOne(targetEntity="Question")
*/
private $question;
// getters and setters
}
My Form entity looks like this:
/**
* Form
*
* @ORM\Table(name="form")
* @ORM\Entity(repositoryClass="Ineat\FormGeneratorBundle\Entity\FormRepository")
* @UniqueEntity("name")
* @UniqueEntity("slug")
*/
class Form
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="slug", type="string", length=255)
*/
private $slug;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Widget", mappedBy="form")
*/
private $widgets;
public function __construct()
{
$this->widgets = new ArrayCollection();
}
// getters and setters
}
And one Widget entity:
/**
* Widget
*
* @ORM\Table(name="widget_choices")
* @ORM\Entity
*/
class WidgetChoices extends Widget
{
/**
* @var array
*
* @ORM\Column(type="array")
*/
private $choices;
// getters and setters
}
Whenever I try to display my form I've got the following error:
Neither property "WidgetText" nor method "getWidgetText()" nor method "isWidgetText()" exists in class "Ineat\FormGeneratorBundle\Entity\Form"
It seems it's like if my widgets weren't extending Widget at all. I need a way to cast my widgets as Widget or a way to tell doctrine that my ArrayCollection can contains everything extending Widget.
Is it possible?