脚本宝典收集整理的这篇文章主要介绍了php – Doctrine 2:在复杂的关系中保存实体,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
/** * @ManyToOne(targetEntity="User",inversedBy="favoriteRecipes") */ PRivate $user; /** * @ManyToOne(targetEntity="Recipe",inversedBy="favoriteRecipes") */ private $recipe;
食谱
/** * @OneToMany(targetEntity="FavoriteRecipe",mappedBy="user") */ private $favoriteRecipes;
/** * @OneToMany(targetEntity="FavoriteRecipe",mappedBy="user") */ private $favoriteRecipes;
$favoriteRecipe = new \Entities\FavoriteRecipe(); $favoriteRecipe->setRecipe($recipe); $favoriteRecipe->setUser($user); $this->_em->persist($favoriteRecipe); $this->_em->flush();
但是这会抛出以下消息的异常:
如何正确创建和保存FavoriteRecipe实体?
也许这个页面:http://www.doctrine-project.org/docs/orm/2.0/en/reference/working-with-associations.html
或者这些视频:
http://www.zendcasts.com/many-to-many-with-doctrine-2/2011/03/
http://www.zendcasts.com/one-to-many-with-doctrine-2/2011/03/
以上是脚本宝典为你收集整理的php – Doctrine 2:在复杂的关系中保存实体全部内容,希望文章能够帮你解决php – Doctrine 2:在复杂的关系中保存实体所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。