次の問題を検討してください。との間に
は多対1の関連付けがArticle
ありAuthor
ます。
class Author{
/**
* ...
*@var ArrayCollection_of_Article
*/
public $articles;
}
class Article{
/**
* ...
*@var Author
*/
public $author;
}
新しいものを作るArticle
私は2つのタイプのコードを持っています:
1つ目:
$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
2番目: (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
どちらが正しいですか?
最初のものは正しく機能します。しかし、2つ目は、次のようなエラーを引き起こすことがあります。
A new entity was found through a relationship that was not configured to cascade persist operations
2つ目が可能かどうか、または常にSQLエラーが発生するかどうかを知りたいです。
ありがとう...