回答

收藏

SQL未插入Yii中具有关系的表

技术问答 技术问答 37 人阅读 | 0 人回复 | 2023-09-12

我试图创建一个用户,所有值都没有插入数据库。systems_user表与表有关,因为party_id是sytems_user主键。没有插入任何东西。即使没有错,它只是回到创建页面。这是我的结构:
& F5 Z+ d- }2 Y" I---- Table structure for table `system_users`--CREATE TABLE IF NOT EXISTS `system_users` (  `party_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `username` varchar(200) NOT NULL, `password` varchar(255) NOT NULL, `date_last_login` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `status` varchar(50) NOT NULL DEFAULT 'Pending for Approval', `date_created` datetime NOT NULL, `date_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',    `user_role` varchar(255) NOT NULL, `isLogin` int(1) NOT NULL, PRIMARY KEY (`party_id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=221 ;---- Constraints for table `system_users`--ALTER TABLE `system_users`  ADD CONSTRAINT `system_users_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`);--------------------------------------- Table structure for table `parties`-- CREATE TABLE IF NOT EXISTS `parties` (   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,        `party_type_id` int(10) unsigned NOT NULL,  PRIMARY KEY (`id`), KEY `party_type_id` (`party_type_id`) ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=200 ;---- Constraints for table `parties`--ALTER TABLE `parties`  ADD CONSTRAINT `parties_ibfk_1` FOREIGN KEY (`party_type_id`) REFERENCES `party_types`    (`id`);我怎么了?为什么不插入?
0 l" n9 @" ~0 c: n编辑
/ l& ~3 ]7 V% C% a/ R/ i4 Y/ gSystemUser模型规则:2 w$ a6 W3 S! O% }' T3 V. w
public function rules()()()()()(///)()()()()()(()()()()()())()()(////)())()()()())()()()///////)()()()())())()())()())())()()()()()()()())()()()()()()())()()()())()()()()()()())()()())()()()())()()()()()()()()()()()()//////)/)/)/)()()()()()()()()()()())()())())())()())()())()())()())()())()()())()())()()()()()())()))()))()))()())())())())()()()())()))()))())())()))()()))()()()))()()()))())())()))())()()())())()))())))))())))()()))())))())))()))()())()())()))()))()()()()()))())))))())())()()()()()))))()))())))))()))))()))())()()))))())()()()()()()()())()))()////////)))))))))))))()))))))))()))))))()()()()()()()())))NOTE: you should only define rules for those attributes that    // will receive user inputs.    return array(         array('username,password,date_last_login,date_created,user_role,isLogin','required     array('isLogin','numerical','integerOnly'=>true),       array('username','length','max'=>200),       array('password,user_role','length','max'=>255),       array('status','length','max'=>50)array('date_modified','safe   The following rule is used by search().     Please remove those attributes that should not be searched.        array('party_id,username,password,date_last_login,status,date_created,date_modified,user_role,isLogin','safe','on'=>'search,  );缔约方规则:
2 u4 B  _# S$ Y+ a; C/ Z# c' p    public function rules()()()()()(///)()()()()()(()()()()()())()()(////)())()()()())()()()///////)()()()())())()())()())())()()()()()()()())()()()()()()())()()()())()()()()()()())()()())()()()())()()()()()()()()()()()()//////)/)/)/)()()()()()()()()()()())()())())())()())()())()())()())()())()()())()())()()()()()())()))()))()))()())())())())()()()())()))()))())())()))()()))()()()))()()()))())())()))())()()())())()))())))))())))()()))())))())))()))()())()())()))()))()()()()()))())))))())())()()()()()))))()))())))))()))))()))())()()))))())()()()()()()()())()))()////////)))))))))))))()))))))))()))))))()()()()()()()())))NOTE: you should only define rules for those attributes that    // will receive user inputs.    return array(         array('party_type_id','required     array('party_type_id','length','max'=>10),       // The following rule is used by search().        // Please remove those attributes that should not be searched.        array('id,party_type_id','safe','on'=>'search,  );编辑控制器actionCreate(); c4 v9 c) h- w$ h1 {0 [
背景知识:$ Y9 n8 K; T, `; m/ Q  [1 s6 F. ^
从下面可以看出,if语句中的条件仅询问是否设置了SystemUsers,因为创造来自SystemUser表格。我的目标是获得。system_user的party_id并插入并插入
# e+ G- Z9 s+ _: {% ?& BParties在表中,个表和我正在使用的一样。SystemUsers模型不同。到目前为止,当我运行这个命令时,我没有反应。
7 N) A# ~0 u6 l% ^1 @* @& w. ?public function actionCreate(){     $parties = new Parties;    $model= new SystemUsers;    // Uncomment the following line if AJAX validation is needed    // $this->performAjaxValidation($model);     if (isset($_POST['SystemUsers)))                                       $parties->attributes = (HOW can I put the party_id from $model here?);                $model->attributes = $_POST['SystemUsers;                            $valid = true;                 $valid &= $parties->validate();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;$valid &= $model->validate();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;if($valid)                                                                                                  $parties->id = $model->getPrimaryKey();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;       $parties->save(); /* First save parties. *                                                     $model->save();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    }            }    $this->render('create',array(   model'=>$model,   'parties'=>$parties,    );               8 Y4 i$ J' w- E0 b; A# [( p
    解决方案:
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则