Answer the question
In order to leave comments, you need to log in
Text field doesn't want to be null?
Good afternoon
I understand with Symfony2, everything seems to be fine, but one hitch does not want to let me go any further. Please help.
There is an Entity Offer, which must have an OfferDescription in all languages of the site. Here are their descriptions:
class Offer<br>
{<br>
/**<br>
* @var integer $id<br>
*<br>
* @ORM\Column(name="id", type="integer", nullable=false)<br>
* @ORM\Id<br>
* @ORM\GeneratedValue(strategy="IDENTITY")<br>
*/<br>
private $id;<br><br>
/**<br>
* @ORM\OneToMany(targetEntity="OfferDescr", mappedBy="offer", cascade={"all"}, orphanRemoval=true )<br>
*/<br>
protected $descriptions;<br><br>
public function __construct()<br>
{<br>
$this->descriptions = new ArrayCollection();<br>
}<br>
}<br><br>
class OfferDescr<br>
{<br>
/**<br>
* @var integer $id<br>
*<br>
* @ORM\Column(name="id", type="integer", nullable=false)<br>
* @ORM\Id<br>
* @ORM\GeneratedValue(strategy="IDENTITY")<br>
*/<br>
private $id;<br><br>
/**<br>
* @var text $h1<br>
*<br>
* @ORM\Column(name="h1", type="text", nullable=true)<br>
*/<br>
private $h1 = '';<br><br>
/**<br>
*<br>
* @ORM\ManyToOne(targetEntity="Offer", inversedBy="descriptions")<br>
* @ORM\JoinColumn(name="offer_id", referencedColumnName="id")<br>
*/<br>
protected $offer;<br>
}<br><br>
class OfferDescrEditForm extends AbstractType<br>
{<br>
public function buildForm(FormBuilder $builder, array $options)<br>
{<br>
$builder->add('lng','hidden');<br>
$builder->add('h1');<br>
}<br>
}<br><br>
class OfferEditForm extends AbstractType<br>
{<br>
public function buildForm(FormBuilder $builder, array $options)<br>
{<br>
$builder->add('descriptions', 'collection', array('type' => new OfferDescrEditForm()));<br>
}<br>
}<br>
if ( $id ) {<br>
// Update offer action<br>
$offer = $this->getOfferTotalInfoArr( $id );<br>
$this->_updOfferAction( $offer );<br>
}else{<br>
// Add new ofer action<br>
$offer = $this -> _initNewOffer();<br>
$this->_updOfferAction( $offer );<br>
}<br>
private function _initNewOffer( ) {<br>
$langs = $this->getLanguages();<br>
$offer = new \PROJ\MainBundle\Entity\Offer();<br><br>
foreach ( $langs as $lng_key => $lng_info ) {<br>
$descr = new \PROJ\MainBundle\Entity\OfferDescr();<br>
$descr->setLng( $lng_key );<br>
$descr->setOffer( $offer );<br><br>
$offer->addOfferDescr( $descr );<br>
}<br>
return $offer;<br>
}<br>
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'h1' cannot be null
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'h2' cannot be null
and so on through the empty fields. sudo php app/console cache:clear --env=dev
doesn't change anything. Answer the question
In order to leave comments, you need to log in
MySQL throws errors. Check that the table does not stand NOT NULL
for these fields.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question