首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在不使用queryBuilder的情况下更新数据库条目

在不使用queryBuilder的情况下更新数据库条目
EN

Stack Overflow用户
提问于 2013-01-30 15:58:11
回答 3查看 24K关注 0票数 11

要将条目保存到数据库,我们可以使用:

代码语言:javascript
运行
复制
$em->persist($entity);
$em->flush();

但是,我们如何在不使用$this->getEntityManager()->createQuery()的情况下更新现有条目?

我们能不能?

我在某种$em->update()中搜索db中的现有条目。

EN

Stack Overflow用户

回答已采纳

发布于 2013-05-18 14:10:01

简单的方法来做,富塞琴说的对,只是展示一个例子

代码语言:javascript
运行
复制
// 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
票数 14
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14599100

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档