<tfoot id='I4eBO'></tfoot>

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

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

        带有复合主键的 Yii 模型

        Yii Model with composite primary key(带有复合主键的 Yii 模型)

            <tbody id='n7JiE'></tbody>
            <bdo id='n7JiE'></bdo><ul id='n7JiE'></ul>

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

                <legend id='n7JiE'><style id='n7JiE'><dir id='n7JiE'><q id='n7JiE'></q></dir></style></legend><tfoot id='n7JiE'></tfoot>

                  <i id='n7JiE'><tr id='n7JiE'><dt id='n7JiE'><q id='n7JiE'><span id='n7JiE'><b id='n7JiE'><form id='n7JiE'><ins id='n7JiE'></ins><ul id='n7JiE'></ul><sub id='n7JiE'></sub></form><legend id='n7JiE'></legend><bdo id='n7JiE'><pre id='n7JiE'><center id='n7JiE'></center></pre></bdo></b><th id='n7JiE'></th></span></q></dt></tr></i><div id='n7JiE'><tfoot id='n7JiE'></tfoot><dl id='n7JiE'><fieldset id='n7JiE'></fieldset></dl></div>
                  本文介绍了带有复合主键的 Yii 模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的 MySQL 表的主表由 2 列组成:space_id (INTEGER) 和 day (DATE).

                  创建表`ck_space_calendar_cache`(`space_id` int(11) 非空,`day` 日期不为空,`available` tinyint(1) 无符号 NOT NULL DEFAULT '0',`价格`十进制(12,2)默认为空,`offer` varchar(45) 默认为空,`presale_date` 日期默认为空,`presale_price` 十进制(12,2)默认为空,`value_x` int(11) 默认为空,`value_y` int(11) 默认为空,PRIMARY KEY (`space_id`,`day`),KEY`空间`(`space_id`),约束`space`外键(`space_id`)引用`ck_space`(`id`)在更新时删除级联无操作) 引擎=InnoDB 默认字符集=utf8;

                  它在原始 SQL 中工作正常,如果我尝试创建重复项,它会抱怨,但让我在同一天或相同的 space_id 创建行.

                  然而,在 Yii 中使用 new Object() 和 save() 时,它会抱怨好像space_id"必须是唯一的.

                  如果重要的话,我使用Giix"来生成模型.

                  我尝试将此代码添加到模型中,但没有帮助:

                  公共函数primaryKey(){return array('space_id', 'day');}

                  解决方案

                  将此代码添加到您的 ActiveRecord 类是可以的,但应该没有必要,因为 Yii 已经从您的 MySQL 表声明中获得了该信息.

                   公共函数primaryKey(){return array('space_id', 'day');}

                  当 Yii 抱怨space_id"是唯一的时,giix 可能在您的 ActiveRecord 类中的 rules() 中添加了验证规则.在保存 ActiveRecord 之前检查这些规则,并且只有在所有规则都正常时才会保存.阅读权威指南的数据验证部分了解更多信息.>

                  My MySQL table's primary is a composite of 2 columns: space_id (INTEGER) and day (DATE).

                  CREATE TABLE `ck_space_calendar_cache` (
                    `space_id` int(11) NOT NULL,
                    `day` date NOT NULL,
                    `available` tinyint(1) unsigned NOT NULL DEFAULT '0',
                    `price` decimal(12,2) DEFAULT NULL,
                    `offer` varchar(45) DEFAULT NULL,
                    `presale_date` date DEFAULT NULL,
                    `presale_price` decimal(12,2) DEFAULT NULL,
                    `value_x` int(11) DEFAULT NULL,
                    `value_y` int(11) DEFAULT NULL,
                    PRIMARY KEY (`space_id`,`day`),
                    KEY `space` (`space_id`),
                    CONSTRAINT `space` FOREIGN KEY (`space_id`) REFERENCES `ck_space` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
                  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
                  

                  It works fine in raw SQL, it complains if I try to create a duplicate, but lets me create rows the the same day or the same space_id.

                  However, in Yii when using new Object() and save(), it complains as if "space_id" has to be unique.

                  I used "Giix" to generate the model if it matters.

                  I tried to add this code to the model, but it didn't help:

                  public function primaryKey(){
                              return array('space_id', 'day');
                          }
                  

                  解决方案

                  Adding this code to your ActiveRecord class is okay, but should not be necessary because Yii already has that information from your MySQL table declaration.

                      public function primaryKey(){
                         return array('space_id', 'day');
                      }
                  

                  When Yii complains about "space_id" to be unique, giix might have added a validation rule to rules() in your ActiveRecord class. These rules are checked before an ActiveRecord is saved and it will only save if all rules are okay. Read the Data Validation section of Definitive Guide for more information.

                  这篇关于带有复合主键的 Yii 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的问题)

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

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

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

                          <tbody id='xi3YV'></tbody>
                        • <legend id='xi3YV'><style id='xi3YV'><dir id='xi3YV'><q id='xi3YV'></q></dir></style></legend>