I have 3 tables in DB:
task_estimation_fields:
CREATE TABLE `task_estimation_fields` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name_UNIQUE` (`name`)
) ENGINE=InnoDB;
task_estimations:
CREATE TABLE `task_estimations` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`task_id` int(11) NOT NULL,
`task_estimation_field_id` int(11) NOT NULL,
`description` blob,
`summary` blob,
`effort` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`created_by` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `g1` (`task_id`),
KEY `g2` (`created_by`),
KEY `g3` (`task_estimation_field_id`),
CONSTRAINT `g1` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `g2` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `g3` FOREIGN KEY (`task_estimation_field_id`) REFERENCES `task_estimation_fields` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB;
tasks:
CREATE TABLE `tasks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`assignee_id` int(11) NOT NULL,
`status_id` int(11) NOT NULL,
`prioryty_id` int(11) NOT NULL,
`title` varchar(45) NOT NULL,
`description` longblob,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
Entity files generated from existing database using following commands:
$ php app/console doctrine:mapping:import --force AcmeBlogBundle xml
$ php app/console doctrine:mapping:convert annotation ./src
$ php app/console doctrine:generate:entities AcmeBlogBundle
In the controler I am getting resulte from database this way:
public function indexAction($id) {
$estimations = $this->getDoctrine()
->getManager()
->createQueryBuilder()
->select('tef, te')
->from('SynapthsisSpecBundle:TaskEstimationFields', 'tef')
->leftJoin('SynapthsisSpecBundle:TaskEstimations', 'te', 'WITH', 'te.taskEstimationField = tef.id AND te.task = :id')
->setParameter('id', $id)
->getQuery()
->getResult();
if (!$this->container->get('request')->isXmlHttpRequest()) {
return $this->render('SynapthsisSpecBundle:TaskEstimation:index.html.twig', array('id' => $id, 'estimations' => $estimations));
} else {
return $this->render('SynapthsisSpecBundle:TaskEstimation:index_ajax.html.twig', array('id' => $id, 'estimations' => $estimations));
}
}
The Twig code is here:
{% extends 'SynapthsisSpecBundle::layout.html.twig' %}
{% block page_contener %}
task estimation index {{ id }}
<hr />
{% for es in estimations %}
{{ es.description }}</br>
{% endfor %}
{% endblock %}
The problem is that I am getting:
Method "description" for object "Synapthsis\SpecBundle\Entity\TaskEstimationFields" does not exist in SynapthsisSpecBundle:TaskEstimation:index.html.twig at line 7
So I thought that I am getting TaskEstimations so i wanted to show "name" field with code like this:
{% extends 'SynapthsisSpecBundle::layout.html.twig' %}
{% block page_contener %}
task estimation index {{ id }}
<hr />
{% for es in estimations %}
{% if null != es %}
{{ es.name }}</br>
{% else %}
aaa </br>
{% endif %}
{% endfor %}
{% endblock %}
I am getting:
Method "effort" for object "Synapthsis\SpecBundle\Entity\TaskEstimationFields" does not exist in SynapthsisSpecBundle:TaskEstimation:index.html.twig at line 7
How can I print results of the query above in the TWIG template?