PHP code example of voskobovich / yii2-many-many-behavior
1. Go to this page and download the library: Download voskobovich/yii2-many-many-behavior library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
voskobovich / yii2-many-many-behavior example snippets
public function getAuthors()
{
return $this->hasMany(Author::className(), ['id' => 'author_id'])
->viaTable('book_has_author', ['book_id' => 'id']);
}
public function getReviews()
{
return $this->hasMany(Review::className(), ['id' => 'review_id']);
}
function($model, $relationName, $attributeName) {
//get db connection from primary model (Book)
$connection = $model::getDb();
...
//OR get db connection from secondary model (Review)
$secondaryModelClass = $model->getRelation($relationName)->modelClass;
$connection = $secondaryModelClass::getDb();
...
//further value calculation logic (db query)