2012-08-12 67 views
1

我想使用CakePHP模型使用枚举文档我的收藏上mogodb:CakePHP的MongoDB的

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', 
      ), 
     ); 

} 

顺便说一句,我可以用这个词整数参考了一些领域?

回答

0

integer类型定义为cakephp-mongodb库中受支持的column mapping。另外,Mark Story在this blog post中提到了这种类型。

在库的代码库中似乎没有提及枚举支持,所以我认为它不被支持。整合EnumerableBehavior库可能会有一些运气;否则,这些选项可以很容易地存储在模型类的静态数组中,并在应用程序中手动验证。请注意,MongoDB没有枚举字段类型(如您在MySQL中所见),因此您的应用程序将负责确保该字段的数据完整性。