dana
dana

Reputation: 5208

Kohana convert database object to int

i have two values. one represents a number of objects

$a = $product->count_all();

and the other represents a value from the database:

$first = Model::factory('product')->sale($sale_id)->find();

i need the sum between the two. the second returns the first id that satsfies the query conditions. how can i convert the $first variable to int in kohana or how can i make this sum?? thank you!

Upvotes: 0

Views: 411

Answers (1)

biakaveron
biakaveron

Reputation: 5483

  1. Use $_ignored_columns for it:

    protected $_ignored_columns = array('count');
    

    So, you can initialize it ($first->count = $a;) and get as a model column ($count = $first->count;).

  2. Create special method get_count() in your model:

    protected $_row_count;
    
    public function get_count()
    {
        if ( $this->_row_count === NULL)
        {
             $this->_row_count = ORM::factory($this->_object_name)->count_all();
        }
    
        return $this->_row_count;
    }
    

Upvotes: 1

Related Questions