i am using kohana ORM in order to get some results from the database. My problem is: even though i have consulted the documentation, i can't find a way to select only the column i am interested in. 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 the "SELECT product_type.* from product_type where etc". But i want to select only the 'stock' field from the salestock table. doing find('stock') instead find_all() returns a weired object... Where am i wrong, and how can i actually select only the column 'stock' using kohana orm?
thank you!
ORM methods find()
and find_all()
always select all table columns, so there is two ways to get specified fields:
$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');
// 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); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With