3
考慮以下問題:
我有一個多到一個協會和Author
之間Article
。學說關聯映射和ArrayCollection的堅持錯誤
class Author{
/**
* ...
*@var ArrayCollection_of_Article
*/
public $articles;
}
class Article{
/**
* ...
*@var Author
*/
public $author;
}
製作一個新Article
我有兩種類型的代碼:
第一之一:
$author = ORM::Find("Author",12); // fetch an Author with ID=12
$art = new Article();
$art->author=$author;
$author->articles->add($art);
ORM::Persist($art); // persist it to write to database
第二之一:(省略第4行)
$author = ORM::Find("Author",12); // fetch an Author with ID=12
$art = new Article();
$art->author=$author;
ORM::Persist($art); // persist it to write to database
哪一個是正確的?
第一個工作正常。但是,第二個導致錯誤,例如下面的錯誤有時:
A new entity was found through a relationship that was not configured to cascade persist operations
我想知道第二個是可能的還是它會總是原因SQL錯誤。
謝謝...
第二次導致任何錯誤?哪一個以防萬一? – moonwave99
第二個導致錯誤**有時** –
根據天氣情況?請發佈整個orm註釋/配置文件,並附帶消息錯誤[是PDO/Mysql錯誤還是PHP錯誤btw?]。 – moonwave99