示例#1
0
 public function translated()
 {
     $messageTableName = Message::tableName();
     $query = Message::find()->select($messageTableName . '.id');
     $i = 0;
     foreach (Yii::$app->i18n->languages as $language) {
         if ($i === 0) {
             $query->andWhere($messageTableName . '.language = :language and ' . $messageTableName . '.translation is not null', [':language' => $language]);
         } else {
             $query->innerJoin($messageTableName . ' t' . $i, 't' . $i . '.id = ' . $messageTableName . '.id and t' . $i . '.language = :language and t' . $i . '.translation is not null', [':language' => $language]);
         }
         $i++;
     }
     $ids = $query->indexBy('id')->all();
     $this->andWhere(['in', 'id', array_keys($ids)]);
     return $this;
 }
示例#2
0
 /**
  * @return $this
  */
 public function getMessages()
 {
     return $this->hasMany(Message::className(), ['id' => 'id'])->indexBy('language');
 }