Skip to content

Commit

Permalink
fix for support any PK name in behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
chiliec committed Jun 3, 2015
1 parent eea679c commit 946fcf4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions behaviors/RatingBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public function events()

public function afterFind($event)
{
if($received_rating = Rating::getRating($this->model_name, $this->owner->id)) {
if ($received_rating = Rating::getRating($this->model_name, $this->owner->{$this->owner->primaryKey()[0]})) {
$rating = $received_rating['likes'] - $received_rating['dislikes'];
$aggregate_rating = $received_rating['aggregate_rating'];
if(($this->owner->{$this->rating_field} != $rating) or ($this->owner->{$this->aggregate_rating_field} != $aggregate_rating)) {
if (($this->owner->{$this->rating_field} != $rating) or ($this->owner->{$this->aggregate_rating_field} != $aggregate_rating)) {
\Yii::$app->db->createCommand()->update(
$this->owner->tableName(),
[$this->rating_field => $rating, $this->aggregate_rating_field => $aggregate_rating],
Expand Down

0 comments on commit 946fcf4

Please sign in to comment.