Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kohana orm order asc/desc?

I heed two variables storing the maximum id from a table, and the minimum id from the same table.

the first id is easy to be taken ,using find() and a query like

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

but how can i retrieve the last id? is there a sorting option in the Kohana 3 ORM? thanks!

like image 353
dana Avatar asked Mar 13 '26 15:03

dana


1 Answers

  1. Yes, you can sort resulting rows in ORM with order_by($column, $order). For example, ->order_by('id', 'ASC').

  2. Use QBuilder to get a specific values:

  public function get_minmax() 
  {
      return DB::select(array('MAX("id")', 'max_id'),array('MIN("id")', 'min_id'))
                 ->from($this->_table_name)
                 ->execute($this->_db); 
  }
like image 111
biakaveron Avatar answered Mar 16 '26 03:03

biakaveron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!