vtvz / yii2-relations
Support simple ActiveRecord relations
Installs: 24
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2020-12-11 22:19:04 UTC
README
Расширение, которое позволяет легко создавать связи между различными ActiveRecord моделями.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist vtvz/yii2-relations
or add
"vtvz/yii2-relations": "*"
to the require section of your composer.json.
Usage
Класс vtvz\relations\Relations является поведением.
Поведение поддерживает все виды связей и позволяет удобно их настраивать.
Пример:
<?php namespace common\models; use vtvz\relations\Relations; class Order extends Model { public function behaviors() { return [ 'relations' => [ 'class' => Relations::className(), 'relations' => [ /* many to many relation type */ 'items' => [ 'model' => Item::className(), 'link' => ['id' => 'itemId'], 'viaTable' => 'order_has_item', 'viaLink' => ['orderId' => 'id'], 'inverseOf' => 'orders', ], /* one (customer) to many (orders) relation type */ 'customer' => [ 'model' => Customer::className(), 'link' => ['id' => 'customerId'], 'type' => 'one', ], /* one to one relation type with delete */ 'orderInfo' => [ 'model' => OrderInfo::className(), 'link' => ['id' => 'id'], 'type' => 'one', 'delete' => true, ], /* many (somethings) to one (order) relation type. All somethings deletes with its order */ 'somethings' => [ 'model' => Something::className(), 'link' => ['orderId' => 'id'], 'type' => 'many', ] ], ], ]; } } ?>
Примечание
Расширение находится на стадии ранней разработки. Нужна помощь в покрытии расширения тестами и создании нормальной документации.