Raakesh Kumar Thu Oct 03 10:12:19 -0400 2013

Subject: Call to undefined method when i try to fetch related table data in Twig

Hi,
I am in serious trouble and have spent a whole day searching and debugging it. Here is the scenario:
I have two models
1 - class Property extends ActiveRecord\Model {
//put your code here
static $belongs_to = array(
array('category')
);
}
2 - class Category extends ActiveRecord\Model{
//put your code here
static $has_many = array(
array('properties')
);
}

Means i have a few properties and they belong to a category i.e. a category can have many properties.
I am using codeigniter as a framework And twig library in my views to display data. Now my problem is i want to fetch all the properties and their corresponding categories and i wrote
public function index() {
$data['properties'] = Property::find('all');
$this->twig->title()->append('Properties');
$this->twig->display('properties/properties',$data);
}

in my Properties controller. and {{property.category.category}} in my view file .. But i am getting following error:
Uncaught exception 'ActiveRecord\ActiveRecordException' with message 'Call to undefined method: category' in /var/www/sewara/application/libraries/php-activerecord/lib/Model.php:1385 Stack trace: #0 [internal function]: ActiveRecord\Model->__call('category', Array) #1 [internal function]: Property->category() #2 /var/www/sewara/application/libraries/Twig/Template.php(437): call_user_func_array(Array, Array) #3 /var/www/sewara/application/cache/twig/3a/e4/1b1245fcfb97c794ecc6d9cb159c.php(69): Twig_Template->getAttribute(Object(Property), 'category') #4 [internal function]: __TwigTemplate_3ae41b1245fcfb97c794ecc6d9cb159c->block_content(Array, Array) #5 /var/www/sewara/application/libraries/Twig/Template.php(133): call_user_func(Array, Array, Array) #6 /var/www/sewara/application/cache/twig/a8/b6/3c6e20422c09342e9bb7de955d04.php(115): Twig_Template->displayBlock('content', Array, Array) #7 /var/www/sewara/application/libraries/Twig/Template.php(264): __TwigTemplate_a8b63c6e20422c09342e9bb7de955d04->doDisplay(Arr in /var/www/sewara/application/libraries/Twig/Template.php on line 279

Later i tried to do it by Property::all(array('include' => array('category'))) this also but no luck :(

I will be highly obliged if you could reply me and solve my problem. I am a big fan of active record and this is my first time i am using it with codeigniter.

Please please help