• <bdo id='6Wqez'></bdo><ul id='6Wqez'></ul>

    <small id='6Wqez'></small><noframes id='6Wqez'>

  1. <i id='6Wqez'><tr id='6Wqez'><dt id='6Wqez'><q id='6Wqez'><span id='6Wqez'><b id='6Wqez'><form id='6Wqez'><ins id='6Wqez'></ins><ul id='6Wqez'></ul><sub id='6Wqez'></sub></form><legend id='6Wqez'></legend><bdo id='6Wqez'><pre id='6Wqez'><center id='6Wqez'></center></pre></bdo></b><th id='6Wqez'></th></span></q></dt></tr></i><div id='6Wqez'><tfoot id='6Wqez'></tfoot><dl id='6Wqez'><fieldset id='6Wqez'></fieldset></dl></div>
  2. <legend id='6Wqez'><style id='6Wqez'><dir id='6Wqez'><q id='6Wqez'></q></dir></style></legend>
      <tfoot id='6Wqez'></tfoot>

      插入具有关联的实体时,有没有办法只使用 FK 而不是检索实体?

      When inserting an entity with associations, is there a way to just use the FK instead of retrieving the entity?(插入具有关联的实体时,有没有办法只使用 FK 而不是检索实体?)

      <legend id='vKQex'><style id='vKQex'><dir id='vKQex'><q id='vKQex'></q></dir></style></legend>
          <tfoot id='vKQex'></tfoot>
        1. <small id='vKQex'></small><noframes id='vKQex'>

            <tbody id='vKQex'></tbody>
          <i id='vKQex'><tr id='vKQex'><dt id='vKQex'><q id='vKQex'><span id='vKQex'><b id='vKQex'><form id='vKQex'><ins id='vKQex'></ins><ul id='vKQex'></ul><sub id='vKQex'></sub></form><legend id='vKQex'></legend><bdo id='vKQex'><pre id='vKQex'><center id='vKQex'></center></pre></bdo></b><th id='vKQex'></th></span></q></dt></tr></i><div id='vKQex'><tfoot id='vKQex'></tfoot><dl id='vKQex'><fieldset id='vKQex'></fieldset></dl></div>

                <bdo id='vKQex'></bdo><ul id='vKQex'></ul>
                本文介绍了插入具有关联的实体时,有没有办法只使用 FK 而不是检索实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要插入一个具有关联的实体.

                I need to insert an entity which has associations.

                如果我已经拥有关联实体的 FK,有没有办法将主要实体插入到仅填充 FK 的数据库中?

                If I already have the FK's of the associated entities, is there a way to insert the primary entity into the db with just the FK's populated?

                或者我总是必须

                • 通过 FK 检索关联实体,
                • 填充涉及关联的主要实体的属性,
                • 然后调用persist方法.

                推荐答案

                你想要一个 引用代理

                假设我有帖子和标签.一个帖子有很多标签.我从用户那里得到了一堆标签,他们检查了一堆复选框.

                Let's say I have Posts and Tags. A Post hasMany Tags. I get a bunch of tags from the user, who checked a bunch of checkboxes.

                以下内容将向现有帖子添加标签,而无需先获取每个标签实体.它通过使用由 EntityManager::getReference() 生成的引用代理来实现:

                The following would add tags to an existing post, without fetching each tag entity first. It does this by using reference proxies, generated by EntityManager::getReference():

                $tag_ids = $_POST['tag_id']; // an array of integers representing tag IDs.
                $post = $em->getRepository('Post')->find($post_id); // returns a Post entity.
                
                foreach($tags_ids as $tid){
                   $post->addTag($em->getReference('Tag',$tid));
                }
                $em->persist($post);
                $em->flush();
                

                这篇关于插入具有关联的实体时,有没有办法只使用 FK 而不是检索实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
              • <small id='f3GIu'></small><noframes id='f3GIu'>

                  • <bdo id='f3GIu'></bdo><ul id='f3GIu'></ul>

                    <tfoot id='f3GIu'></tfoot>
                      • <i id='f3GIu'><tr id='f3GIu'><dt id='f3GIu'><q id='f3GIu'><span id='f3GIu'><b id='f3GIu'><form id='f3GIu'><ins id='f3GIu'></ins><ul id='f3GIu'></ul><sub id='f3GIu'></sub></form><legend id='f3GIu'></legend><bdo id='f3GIu'><pre id='f3GIu'><center id='f3GIu'></center></pre></bdo></b><th id='f3GIu'></th></span></q></dt></tr></i><div id='f3GIu'><tfoot id='f3GIu'></tfoot><dl id='f3GIu'><fieldset id='f3GIu'></fieldset></dl></div>
                        <legend id='f3GIu'><style id='f3GIu'><dir id='f3GIu'><q id='f3GIu'></q></dir></style></legend>
                          <tbody id='f3GIu'></tbody>