thomas silva thomas silva - 21 days ago 4x
MySQL Question

Display the last joined entity columns in Twig template

I'm making a website for performance monitoring, so every months people's fill their performances and this create a graph in JavaScript.

I did a ManyToOne relation between performances entity and users entity. As you can see here:

I would like to display the performances of one user for example I use this code in Twig (and after I would like to know how to display the latest performances).

Entity performances:

enter image description here

{% for user in users %}

<h4>{{ user.username|upper }}</h4>
<p>Ville: {{ user.performances.ville }}</p>
<p>Taille: {{ user.performances.taille }}</p>

{% endfor %}

* @ORM\ManyToOne(targetEntity="Users", inversedBy="descriptions")
* @ORM\JoinColumn(name="users_id", referencedColumnName="id")
private $user;

But it don't works, can you guys help me?


If you want to access to the last item of your user.performances collection :

{% for user in users  %}
    <h4>{{ user.username|upper }}</h4>
    <p>Ville: {{ user.performances.last.ville  }}</p>
    <p>Taille: {{ user.performances.last.taille  }}</p>
{% endfor %}

You can do the same with first for the first item.