Commit fc0490a4 authored by Shakarim Sapa's avatar Shakarim Sapa

Merge remote-tracking branch 'origin/master'

parents da5a6629 73c5f333
......@@ -5,6 +5,7 @@ namespace common\modules\blog\models;
use Yii;
use common\modules\blog\models\Post;
use common\modules\blog\models\PostTagAssign;
/**
* This is the model class for table "posts_tags".
......@@ -64,4 +65,12 @@ class PostTag extends \common\components\ActiveRecordModel
{
return $this->hasMany(Post::className(), ['id' => 'post_id'])->viaTable('posts_tags_assign', ['tag_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getAssigns()
{
return $this->hasMany(PostTagAssign::className(), ['tag_id' => 'id']);
}
}
......@@ -14,7 +14,12 @@ use common\models\Settings;
<h2>Категории</h2>
<div class="sidebar_module_body">
<?php $tags = PostTag::find()->orderBy('RAND()')->limit(7)->all();
<?php $tags = PostTag::find()
->innerJoinWith('assigns')
->groupBy(['posts_tags_assign.tag_id'])
->orderBy('RAND()')
->limit(7)
->all();
foreach ($tags as $tag) : ?>
<a href="#" class="cat_link_mod"><?=$tag->name?></a>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment