Skip to content

Commit

Permalink
Merge pull request #492 from daniel-aranda/model_cast_count_as_integer
Browse files Browse the repository at this point in the history
Model cast count as integer
  • Loading branch information
koenpunt committed Jun 3, 2017
2 parents 1523023 + 8bfb68b commit 352e1b6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ public static function count(/* ... */)
$table = static::table();
$sql = $table->options_to_sql($options);
$values = $sql->get_where_values();
return static::connection()->query_and_fetch_one($sql->to_s(),$values);
return (int) static::connection()->query_and_fetch_one($sql->to_s(),$values);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions test/ActiveRecordFindTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ public function test_fetch_all()

public function test_count()
{
$this->assert_equals(1,Author::count(1));
$this->assert_equals(2,Author::count(array(1,2)));
$this->assert_same(1,Author::count(1));
$this->assert_same(2,Author::count(array(1,2)));
$this->assert_true(Author::count() > 1);
$this->assert_equals(0,Author::count(array('conditions' => 'author_id=99999999999999')));
$this->assert_equals(2,Author::count(array('conditions' => 'author_id=1 or author_id=2')));
$this->assert_equals(1,Author::count(array('name' => 'Tito', 'author_id' => 1)));
$this->assert_same(0,Author::count(array('conditions' => 'author_id=99999999999999')));
$this->assert_same(2,Author::count(array('conditions' => 'author_id=1 or author_id=2')));
$this->assert_same(1,Author::count(array('name' => 'Tito', 'author_id' => 1)));
}

public function test_gh149_empty_count()
Expand Down

0 comments on commit 352e1b6

Please sign in to comment.