/** * 获取指定用户的赞记录 * @param null|int $authorId * @return mixed */ public function getLike($authorId = null) { return $this->hasOne(Like::className(), ['target_id' => 'id'])->andWhere(['target_type' => self::TYPE, 'author_id' => $authorId ?: Yii::$app->getUser()->getId()]); }
/** * 获取赞记录 * @return mixed */ public function getLike() { return $this->hasOne(Like::className(), ['target_id' => 'id'])->andWhere(['uid' => Yii::$app->user->getId(), 'target_type' => static::TYPE, 'type' => 'like']); }
/** * 获取用户喜欢列表 * @return static */ public function getLikes() { return $this->hasMany(Like::className(), ['author_id' => 'id'])->inverseOf('author'); }