generateRules() public method

public generateRules ( $table )
Ejemplo n.º 1
0
 /**
  * Generates the rules for table fields.
  * #MethodTracker
  * This method overrides {@link ModelCode::generateRules}, from version 1.1.7 (r3135). Changes:
  * <ul>
  * <li>Adds the rule to fill empty attributes with null.</li>
  * </ul>
  * @param CDbTableSchema $table The table definition.
  * @return array The rules for the table.
  */
 public function generateRules($table)
 {
     $rules = array();
     $null = array();
     foreach ($table->columns as $column) {
         if ($column->autoIncrement) {
             continue;
         }
         if (!(!$column->allowNull && $column->defaultValue === null)) {
             $null[] = $column->name;
         }
     }
     if ($null !== array()) {
         $rules[] = "array('" . implode(', ', $null) . "', 'default', 'setOnEmpty' => true, 'value' => null)";
     }
     return array_merge(parent::generateRules($table), $rules);
 }