0

I was wondering how to work with kohana orm and inheritances.

Supose I have a model called Vehicle

$_table_columns with 5 columns

The lets supose I create another model called Car and I want to add 5 more columns to the model. How should I modify the parent $_table_columns variable or should I override it?

Thanks

jameslimousin
  • 330
  • 3
  • 11

1 Answers1

0

I suppose you're looking for something like this protected $_table_columns = parent::_table_columns + array(...);. Unfortunatly PHP won't allow for this, so you will have to either override $_table_columns and list all 10 columns or override ORM reload_columns method like this:

public function reload_columns($force = FALSE)
{
   $this->_table_columns = parent::_table_columns + array(...);
   parent::reload_columns($force);
}
matino
  • 17,199
  • 8
  • 49
  • 58
  • Hi Matino, thanks for your response. Why do you say that php wont allow is for the protected property or for the '+' sign? Either way what does the reload_columns does? – jameslimousin Nov 04 '11 at 21:02
  • would it be posible to do something like this http://stackoverflow.com/questions/3859155/is-there-a-way-to-override-model-properties-without-defining-them-all-again-with but with the columns array? – jameslimousin Nov 04 '11 at 21:06
  • reload_columns is the native ORM function, where $_table_columns are being initialized. So if you override this function the way I wrote, you could initialize it like you asked. – matino Nov 05 '11 at 08:21
  • Matino, what I did is extend the parent class and on the constructor of the class I did $this->_table_columns = $this->_table_columns + array(...) and after this I called the parent constructor. I seem to be working but then I removed some fields from the array but the model kept loading the fields and that is why I asked this question. http://stackoverflow.com/questions/8017337/kohana-columns-introspection/8019155#8019155 which you answer as well so thank you for all your help – jameslimousin Nov 06 '11 at 17:04