我想使用另一个参数
创建一个新模型class Beacon extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'name';
/**
* Validation rules
*
* @var array
*/
public $validate = array(
'UUID' => array(
'uuid' => array(
'rule' => array('uuid'),
),
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* hasOne associations
*
* @var array
*/
public $hasOne = array(
'Position' => array(
'className' => 'Position',
'foreignKey' => 'beacon_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
我想ping这个信标传递参数信标UUID而不是主键。
class Ping extends AppModel {
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Beacon' => array(
'className' => 'Beacon',
'foreignKey' => 'beacon_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
如何在没有beacon primary_key但是UUID?
的情况下创建Ping对象 在ping控制器上我想添加public function pingBeaconWithUUID($uuid) {
我该如何管理? 谢谢!
答案 0 :(得分:0)
如果UUID是唯一的,您可以将其用作id字段的值。 id不需要是整数,尽管它更可取。
但我也建议使用AgRizzo的方法并查找id。