I'm trying to regerate slug for entities that I've created prior to install Sluggable extension for Doctrine2 as it's explained here: Regenerating slug, but when I set it to empty string or null, does not regerate it, it simply sets as null.
What I'm doing wrong?
The entity:
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity
* @ORM\Table(name="product")
*/
class Product
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=200)
* @Assert\NotBlank()
*/
protected $name;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank()
*/
protected $description;
...
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(length=200, unique=true)
*/
private $slug;
public function getSlug()
{
return $this->slug;
}
public function setSlug($slug)
{
$this->slug = $slug;
}
}
And then I try this:
$repository = $this->getDoctrine()->getRepository('CommonBundle:Product');
$product = $repository->findOneBy(array("id"=>1));
$product->setSlug('');
$em = $this->getDoctrine()->getEntityManager();
$em->persist($product);
$em->flush();