title: SQL not inserting into table with relation in Yii
body: <p>I'm trying to create a user and all the values are not inserting into the database. The systems_user table has a relation to a parties table as the party_id is the primary key of the sytems_user. Nothing is being inserted. Not even an error, it just goes back to the "create" page. Here is my schema:</p>
  
  <pre><code>--
  -- 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`);
  </code></pre>
  
  <p>Where have I gone wrong? Why is it not inserting?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Rules for SystemUser Model:</p>
  
  <pre><code>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'=&gt;true),
          array('username', 'length', 'max'=&gt;200),
          array('password, user_role', 'length', 'max'=&gt;255),
          array('status', 'length', 'max'=&gt;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'=&gt;'search'),
      );
  }
  </code></pre>
  
  <p>Rules for Parties:</p>
  
  <pre><code> 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'=&gt;10),
          // The following rule is used by search().
          // Please remove those attributes that should not be searched.
          array('id, party_type_id', 'safe', 'on'=&gt;'search'),
      );
  }
  </code></pre>
  
  <p><strong>EDIT Controller actionCreate()</strong></p>
  
  <p><strong>A little background:</strong> as you can see from below, the conditions inside the if statement is only asking if the SystemUsers is set because the create come from the SystemUser form. My goal is to get the party_id of the system_user and insert it into the Parties table which is a different model from the SystemUsers that i'm using. So far when I run this, nothing happens.</p>
  
  <pre><code>public function actionCreate()
  {
      $parties = new Parties;
      $model= new SystemUsers;
  
      // Uncomment the following line if AJAX validation is needed
      // $this-&gt;performAjaxValidation($model);
  
       if (isset($_POST['SystemUsers']))
              {
                  $parties-&gt;attributes = (HOW can I put the party_id from $model here?);
                  $model-&gt;attributes = $_POST['SystemUsers'];
                  $valid = true; 
                  $valid &amp;= $parties-&gt;validate(); 
                  $valid &amp;= $model-&gt;validate(); 
  
                  if($valid)
                      {
                          $parties-&gt;id = $model-&gt;getPrimaryKey();
                          $parties-&gt;save(); /* First save parties. */
  
                          $model-&gt;save(); 
                      }
              } 
  
      $this-&gt;render('create',array(
      'model'=&gt;$model,
      'parties'=&gt;$parties, 
      ));
  </code></pre>