Skip to content

Commit

Permalink
#370: A small fix of a bug if the primary keys are ambiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
scoumbourdis committed Sep 28, 2016
1 parent 20b6902 commit fbf9f85
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions application/models/Grocery_crud_model.php
Expand Up @@ -177,19 +177,21 @@ function limit($value, $offset = '')

function get_total_results()
{
// A fast way to calculate the total results
$key = $this->get_primary_key();

//set_relation_n_n special queries. We prefer sub queries from a simple join for the relation_n_n as it is faster and more stable on big tables.
if(!empty($this->relation_n_n))
{
$select = "{$this->table_name}.*";
$select = "{$this->table_name}." . $key;
$select = $this->relation_n_n_queries($select);

$this->db->select($select,false);
}

// A fast way to calculate the total results
$key = $this->get_primary_key();
$this->db->select($key);
return $this->db->get($this->table_name)->num_rows();
} else {
$this->db->select($this->table_name . '.' . $key);
}

return $this->db->get($this->table_name)->num_rows();
}

function set_basic_table($table_name = null)
Expand Down

0 comments on commit fbf9f85

Please sign in to comment.