我正试图让一个物体的场地变得可以穿透。
模型看起来像:
namespace myBundle\Bundles\BlogBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* myBundle\Bundles\BlogBundle\Entity\Category
*
* @ORM\Table()
* @ORM\Entity
*/
class Category
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string $title
*
* @Gedmo\Sluggable
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @Gedmo\Slug(separator="-", updatable=false, unique=true)
* @ORM\Column(name="slug", type="string", length=255, unique=true)
*/
private $slug;
// other properties and methods
赛程:
namespace myBundle\Bundles\BlogBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use tooMuch\Bundles\BlogBundle\Entity\Category;
class LoadCategoryData extends AbstractFixture implements OrderedFixtureInterface
{
public function load($manager)
{
$this->generateCategory($manager);
}
public function generateCategory($manager)
{
for ($i=0; $i < 10; $i++) {
$category = new Category();
$category->setTitle('Category '.$i);
$manager->persist($category);
$manager->flush();
$this->addReference('category'.$i, $category);
unset($category);
}
}
架构创建:
# sf doctrine:schema:create
ATTENTION: This operation should not be executed in a production environment.
Creating database schema...
Database schema created successfully!
但是当我试图添加灯具时:
# sf doctrine:fixtures:load
> purging database
> loading myBundle\Bundles\BlogBundle\DataFixtures\ORM\LoadCategoryData
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'slug' cannot be null
doctrine:fixtures:load [--fixtures[="..."]] [--append] [--em="…"]
#
任何想法?
答案 0 :(得分:1)
问题不在于固定装置,而是在Slug一代本身。如果设置正确,您永远不应该$slug
作为null
您确定附加了Sluggable侦听器吗?