astraller/yii2-mongodb-embedded
Composer 安装命令:
composer require astraller/yii2-mongodb-embedded
包简介
Yii2 extension to work with embedded documents in MongoDB.
README 文档
README
Yii2 extension to work with embedded documents in MongoDB.
This extension requires MongoDB PHP Extension version 1.0.0 or higher.
This extension requires MongoDB server version 3.0 or higher.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist astraller/yii2-mongodb-embedded
or add
"astraller/yii2-mongodb-embedded": "^1.*"
to the require section of your composer.json.
Usage
- Your model must be inherited from astraller\mongodb\MongoModel class.
- Add embedAttributes method
public function embedAttributes() { return [ 'conditions' => [ 'class' => DialogConditions::class, 'type' => 'many', ], 'text' => [ 'class' => Text::class, 'type' => 'one', ], 'variants' => [ 'class' => Dialog::class, 'type' => 'manyById' ] ]; }
- Your embedded documents must be inherited from EmbeddedDocument class.
<?php namespace app\models; use astraller\mongodb\MongoEmbedModel; class Vector3 extends MongoEmbedModel { public $x; public $y; public $z; public function rules() { return [ [['x', 'y', 'z'], 'required'], ]; } public function t(){ return "[X: {$this->x}; Y: {$this->y}; Z: {$this->z}]"; } }
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-25