Код: Выделить всё
class Page {
/**
* @ORM\Column(type="string", unique=true, nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="UUID")
* @var string
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="Url", mappedBy="content")
* @var Url[]
*/
protected $urls;
public function __construct()
{
$this->urls = new ArrayCollection();
}
}
Код: Выделить всё
class Url
{
/**
* @ORM\Id @ORM\Column(type="string", unique=true, nullable=false)
* @ORM\GeneratedValue(strategy="UUID")
* @var string The unique identifier for the Url
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Page", inversedBy="urls", cascade={"persist", "merge"})
* @ORM\JoinColumn(name="content_id", referencedColumnName="id")
* @var int The UUID of the content
*/
protected $content;
public function __construct(Page $content, $link)
{
$this->content = $content;
$this->content->addUrl($this);
}
}
Код: Выделить всё
$pageManager->save($post);
$url = new Url($post, 'link goes here');
$urlManager->save($url);
Код: Выделить всё
$url = new Url($post, 'link goes here');
$pageManager->save($post);
$urlManager->save($url);
( ! ) Неустранимая ошибка: неперехваченное исключение 'Doctrine\ORM\ ORMInvalidArgumentException» с сообщением «Управляемый + грязный объект Page@000000003d5a4ca10000000133ba3c3e не может быть запланирован для вставка.'
Я пробовал это как с использованием AnnotationReader, так и без него, используя EntityManager::create()
Валидатор схемы Doctrine также не сообщает об ошибках:
Код: Выделить всё
php vendor/bin/doctrine orm:validate-schema
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
Подробнее здесь: https://stackoverflow.com/questions/384 ... -insertion