数据库 – Symfony2,Doctrine,更新没有queryBuilder的db条目
发布时间:2020-05-29 16:30:10 所属栏目:MsSql 来源:互联网
导读:为了保存对db的输入,我们可以使用: $em-persist($entity);$em-flush(); 但是,如何使用$this- getEntityManager() – createQuery()可以更新现有条目? 我们可以吗? 我正在为db中的现有条目搜索某种$em- update(). 简单的做法,Fusselchen说的对,只是举个例子
|
为了保存对db的输入,我们可以使用: $em->persist($entity); $em->flush(); 但是,如何使用$this-> getEntityManager() – > createQuery()可以更新现有条目? 我们可以吗? 我正在为db中的现有条目搜索某种$em-> update(). 解决方法简单的做法,Fusselchen说的对,只是举个例子// get entity manager
$em = $this->getDoctrine()->getEntityManager();
// get from this entity manager our "entity" object in $item
// also we can get arrayCollection and then do all in foreach loop
$item = $em->getRepository('repoName')->findOneBy($filter);
// change "entity" / object values we want to edit
$item->setSome('someText')
//...
// call to flush that entity manager from which we create $item
$em->flush();
// after that in db column 'some' will have value 'someText'
// btw after call flush we can still use $item as 'selected object' in
// another $em calls and it will have actual (some = 'someText') values (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
