Reputation: 115
how to create virtual column on Doctrine Symfony2
i have two table
table Company
---------------------------------
id | company_name | address
---------------------------------
1 | sample Co Ltd | NY
2 | company Co Ltd | LA
---------------------------------
table Ships
---------------------------------
id | company_id | ships_name
---------------------------------
1 | 1 | Ship ABC
1 | 1 | Ship XYZ
---------------------------------
how to create query with virtual column (total_ships) in doctrine symfony2, so i can display with data like this in twig template:
{% for entity in pagination %}
<tr>
<td>{{ entity.company_name }}</a></td>
<td>{{ entity.total_ships }}</td>
</tr>
{% endfor %}
Can i add query on Entity Class of Company? Please give me a clue, Thanks Best Regards, Rampak
Upvotes: 0
Views: 2764
Reputation: 493
You need to specify the Entities relationship in their Entity classes.
http://doctrine-orm.readthedocs.org/en/latest/reference/association-mapping.html
and
http://symfony.com/doc/current/book/doctrine.html#entity-relationships-associations
When you have done that and updated your schema, you can do this in Twig:
{{ company.ships|length }}
To get a count. You can also do any type of operatios like
All you need to do is pass a Company object to Twig and Twig + Doctrine will handle everything for you.
Upvotes: 1