Esempio n. 1
0
 /**
  * Find by my ID and my friends.
  *
  * @param $id
  * @return $this
  */
 public function meAndMyFriends($id)
 {
     $modelClass = $this->modelClass;
     $statusTableName = $modelClass::tableName();
     $relationTableName = Relation::tableName();
     $userTableName = User::tableName();
     return $this->innerJoin(Relation::tableName(), $relationTableName . '.following_id = ' . $statusTableName . '.author_id OR ' . $relationTableName . '.follower_id = ' . $statusTableName . '.author_id')->innerJoin(User::tableName(), $relationTableName . '.following_id = ' . $userTableName . '.id OR ' . $relationTableName . '.follower_id = ' . $userTableName . '.id')->andWhere([User::tableName() . '.id' => $id])->orderBy($statusTableName . '.created_at DESC');
 }
Esempio n. 2
0
 /**
  * @return $this
  */
 public function getFriends()
 {
     $relationTableName = Relation::tableName();
     return self::find()->leftJoin($relationTableName, $relationTableName . '.following_id = ' . self::tableName() . '.id OR ' . $relationTableName . '.follower_id = ' . self::tableName() . '.id')->where($relationTableName . '.following_id = :id OR ' . $relationTableName . '.follower_id = :id', [':id' => $this->id])->andWhere(self::tableName() . '.id != :id', [':id' => $this->id]);
 }