array( 'notBlank' => array( 'rule' => array('notBlank'), // The column has no default, so a model added without a name is refused by MySQL. 'required' => 'create', 'message' => 'Name is required', 'last' => true), 'unique' => array( 'rule' => array('isUniquePerManufacturer'), 'message' => 'That manufacturer already has a model with that name')), 'ManufacturerId' => array( 'unique' => array( 'rule' => array('isUniquePerManufacturer'), 'message' => 'That manufacturer already has a model with that name')), 'Id' => array( 'numeric' => array( 'rule' => array('numeric'), //'message' => 'Your custom message here', //'allowEmpty' => false, //'required' => false, //'last' => false, // Stop validation after this rule //'on' => 'create', // Limit validation to 'create' or 'update' operations ), ), ); public function isUniquePerManufacturer($check) { $row = array(); foreach (array('Name', 'ManufacturerId') as $field) { $row[$field] = array_key_exists($field, $this->data[$this->alias]) ? $this->data[$this->alias][$field] : ($this->id ? $this->field($field) : null); } if ($row['ManufacturerId'] === null or $row['ManufacturerId'] === '') return true; // AppModel::beforeValidate() already refuses an array. foreach ($row as $value) { if ($value !== null and !is_scalar($value)) return true; } $conditions = array('CameraModel.Name' => $row['Name'], 'CameraModel.ManufacturerId' => $row['ManufacturerId']); if ($this->id) $conditions['CameraModel.Id !='] = $this->id; return $this->find('count', array('conditions' => $conditions)) === 0; } //The Associations below have been created with all possible keys, those that are not needed can be removed /** * hasMany associations * * @var array */ public $belongsTo = array( 'Manufacturer' => array( 'className' => 'Manufacturer', 'foreignKey' => 'ManufacturerId', ), ); //var $actsAs = array( 'Containable' ); }