vtvz / yii2-extrelations
Support extended ActiveRecord relations
Installs: 16
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
This package is auto-updated.
Last update: 2024-10-29 04:47:24 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', ] ], ], ]; } } ?>
Примечание
Расширение находится на стадии ранней разработки. Нужна помощь в покрытии расширения тестами и создании нормальной документации.