Kohana ORM question

I use kohana ORM to get some results from the database. My problem is that although I consulted the documentation, I cannot find a way to select only the column that interests me. To be more explicit, I have:

$sale_stock = Model::factory('product_type')
->where('product_type_id','=', $id )
-> find_all();

var dumping it, it selects me all "SELECT product_type. * from product_type, where, etc.". But I want to select only the "stock" field from the salestock table. do find ('stock') instead of find_all () returns an object with a binding ... Where am I mistaken, and how can I actually only select the "margin" of a column using kohana orm?

Thank you!

+5
source share
3 answers

ORM find() find_all() , :

  • :
$sale_stock = Model::factory('product_type')
   ->where('product_type_id','=', $id )
   -> find_all();
// get array of id=>stock values
$columns = $sale_stock->as_array('id', 'stock');
  • , Query Builder:
// model Model_Product_Type 
public function get_stocks($product_type_id) 
{    
   return DB::select(array('stock'))
      ->from($this->_table_name)
      ->where('product_type_id', '=', $product_type_id)
      ->execute($this->_db); 
}
+5

, , , Kohana :

$articles = ORM::factory('article')->select_list('id', 'title');

foreach ($articles as $id => $title)
{
    // Display a list of links
    echo html::anchor('articles/'.$id, $title);
}

// Display a dropdown list
echo form::dropdown('articles', $articles);

, .

ORM "", . (.. , 2 8 , ?).

_r , ... , .

0

, , :

$sale_stock = ORM::factory('product_type')
   ->where( 'product_type_id','=', $id )
   ->find_all();
die($sale_stock->stock);
0

All Articles