我想使用cakephp模型在mogodb上为我的集合使用枚举文档:
class Profile extends AppModel {
public $primaryKey = '_id';
var $mongoSchema = array(
'firstname' => array('type'=>'string'),
'lastname'=>array('type'=>'string'),
'adress'=>array('type'=>'string'),
'tel'=>array('type'=>'integer'),
'location'=>array(
'city' => array('type'=>'string'),
'country' => array('type'=>'string'),
'street' => array('type'=>'string'),
'zip' => array('type'=>'integer'),
),
'created'=>array('type'=>'datetime'),
'modified'=>array('type'=>'datetime'),
'corporation'=>array(
'name' => array('type'=>'string'),
'description' => array('type'=>'string'),
'link' => array('type'=>'string'),
'logo' => array('type'=>'string'),
),
'gender'=>array(
'male' => 'Male',
'female' => Female,
'unspecified' => 'Unspecified',
),
);
}顺便问一下,我可以使用整数这个词来引用数字字段吗?
发布于 2012-08-14 03:05:15
在cakephp-mongodb库中,integer类型被定义为受支持的column mapping。此外,Mark Story在this blog post中提到了这种类型。
在库的代码库中似乎没有对枚举支持的引用,所以我假设它不受支持。您可能有幸集成了EnumerableBehavior库;否则,这些选项很容易存储在模型类上的静态数组中,并在您的应用程序中手动验证。请注意,MongoDB没有枚举字段类型(您可能会在MySQL中找到),因此无论采用哪种方式,您的应用程序都将负责确保字段的数据完整性。
https://stackoverflow.com/questions/11919163
复制相似问题