只是想知道如何设置YiiMongodbsuite的独特字段? 我检查了YiiMongodbsuite文件,找不到任何相关内容。
答案 0 :(得分:2)
索引(也是唯一索引)应该在indexes
方法中定义,这里有一些示例from docs:
class Client extends EMongoDocument
{
public function indexes()
{
return array(
// index name is not important, you may write whatever you want, just must be unique
'index1_name'=>array(
// key array holds list of fields for index
// you may define multiple keys for index and multikey indexes
// each key must have a sorting direction SORT_ASC or SORT_DESC
'key'=>array(
'field_name'=>EMongoCriteria::SORT_ASC
'field_name.embeded_field'=>EMongoCriteria::SORT_DESC
),
// unique, if indexed field must be unique, define a unique key
'unique'=>true,
),
);
}
// ....
}
同时检查mongo db suite包中的UniqueValidator
以与yii验证器一起使用。