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

      <tfoot id='zm6JL'></tfoot>

        <small id='zm6JL'></small><noframes id='zm6JL'>

      1. 复制 AR 记录 &amp;将其重新插入数据库

        Duplicate an AR record amp; re-insert this into the database(复制 AR 记录 amp;将其重新插入数据库)

        1. <small id='eV10Q'></small><noframes id='eV10Q'>

            <legend id='eV10Q'><style id='eV10Q'><dir id='eV10Q'><q id='eV10Q'></q></dir></style></legend>
              <bdo id='eV10Q'></bdo><ul id='eV10Q'></ul>

                  <i id='eV10Q'><tr id='eV10Q'><dt id='eV10Q'><q id='eV10Q'><span id='eV10Q'><b id='eV10Q'><form id='eV10Q'><ins id='eV10Q'></ins><ul id='eV10Q'></ul><sub id='eV10Q'></sub></form><legend id='eV10Q'></legend><bdo id='eV10Q'><pre id='eV10Q'><center id='eV10Q'></center></pre></bdo></b><th id='eV10Q'></th></span></q></dt></tr></i><div id='eV10Q'><tfoot id='eV10Q'></tfoot><dl id='eV10Q'><fieldset id='eV10Q'></fieldset></dl></div>
                    <tbody id='eV10Q'></tbody>
                • <tfoot id='eV10Q'></tfoot>
                  本文介绍了复制 AR 记录 &amp;将其重新插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个想要复制的 AR 模型,但只需要手动更改外键.

                  I have a AR model that I am trying to duplicated but just need to manually change the foreign key.

                  $_POST['competition_id'] = 99;
                  $prizes = CompetitionPrizes::model()->findAll('competition_id =:competition_id',array(':competition_id'=> $_POST['competition_id']));
                  

                  这个查询基本上是查询奖品表并获取特定比赛的所有行.对于奖品对象,我想基本上重新插入/复制相同的信息,除了我想手动设置的比赛 ID.

                  This query basically queries the prizes table and gets all the rows for a particular competition. With the prizes object I would like to basically re-insert/duplicate the same information except the competition id which I want to manually set.

                  我对基本上只有一行并且效果很好的 AR 对象做了类似的事情,但是在这种情况下,因为比赛可以有多个奖项,所以相同的代码不会.

                  I did something similar for an AR object that basically only has one row and that worked well, however in this instance as a competition can have more than one prize this same code won't.

                  // My existing code for duplication process
                  $obj = Competitions::model()->find('competition_id=:competition_id', array(':competition_id' => $post['competition_id']));
                  $clone = clone $obj;
                  $clone->isNewRecord = true;
                  unset($clone->competition_id); // i want to remove this so it is auto inserted instead via the db
                  $clone->save();
                  

                  这很好用 - 我如何在奖品的集合"上修改它,并在设置我自己的competition_id"值时将其复制到数据库中.

                  This works great - how would I modify this on a 'collection' of prizes and have this duplicated into the database while setting my own 'competition_id' value.

                  注意 - 我是 Yii 的新手,所以如果我犯了任何明显的错误/不好的做法,请告诉我

                  Note - i'm to new to Yii, so please let me know if I have made any obvious errors/bad practice

                  推荐答案

                  克隆不起作用.您需要将属性分配给新对象:

                  Cloning won't work. You need to assign the attributes to a new object:

                  $obj = Competitions::model()->find('competition_id=:competition_id', array(':competition_id' => $post['competition_id']));
                  $clone = new Competitions;
                  $clone->attributes = $obj->attributes;
                  $clone->save();
                  

                  这篇关于复制 AR 记录 &amp;将其重新插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                • <small id='DmCaR'></small><noframes id='DmCaR'>

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

                          <tfoot id='DmCaR'></tfoot>
                            <tbody id='DmCaR'></tbody>