Every time I try to instantiate a certain model and use it, like for example:
$categories = Model::factory('category')->by_sale($id)->find_all();
I get a weird error. If i have i bootstrap in kohana::init set 'errors' => TRUE,the error is: Could not execute Model_Category::__construct()
else i get only a warning Warning: array_keys() expects parameter 1 to be array, null given in /application/classes/model.php on line 42
meaning here:
private function _get_real_property_name($property)
{
if (isset($this->_belongs_to[$property]) OR
isset($this->_has_one[$property]) OR
isset($this->_has_many[$property]))
return $property;
$column_prefix = $this->_table_name . '_';
$property_prefix = substr($property, 0, strlen($column_prefix));
if ($property_prefix != $column_prefix)
{
$prefixed_property = $column_prefix . $property;
if (in_array($prefixed_property, array_keys($this->table_columns())))
{
return $prefixed_property;
}
}
return $property;
}
The category model looks like this:
class Model_Category extends Model {
/**
* @see ORM::_table_name
*
* @var array
*/
protected $_table_name = 'category';
/**
* @see ORM::_primary_key
*
* @var array
*/
protected $_primary_key = 'category_id';
/**
* @see ORM::_belongs_to
*
* @var array
*/
protected $_belongs_to = array(
'parent' => array('model' => 'category', 'foreign_key' => 'category_category'),
'sale' => array('foreign_key' => 'category_sale')
);
/**
* @see ORM::_has_many
*
* @var array
*/
protected $_has_many = array(
'products' => array('model' => 'product', 'foreign_key' => 'product_category')
);
/**
* Adds the 'top_level' condition to the query
*
* @return Model_Sale
*/
public function top_level()
{
return $this->where('category_category', '=', 0);
}
/**
* Adds the 'by_sale' condition to the query
*
* @return Model_Sale
*/
public function by_sale($sale_id)
{
return $this->where('category_sale', '=', $sale_id);
}
public function __get($property)
{
if ($property == 'siblings')
{
return $this->where('category_sale', '=', $this->sale->id)
->where('category_category', '=', $this->category_category);
}
if ($property == 'children')
{
return $this->where('category_category', '=', $this->pk());
}
return parent::__get($property);
}
} // End Model_Category
Thank you!