samedi 27 juin 2015

Symfony2 twig print values from query on 2 non related tables

I have 2 entities: "Requests" and "Partners" There is a 1to1 relation between Requests and Partners so there is a partners_id field in Requests table I want to display a Partners list, but I need to take a value from a "price" field in Requests table

On my controller I have this query:

$listPartners = $em
    ->getRepository('OandPboBundle:Partners')
    ->createQueryBuilder('p')
    ->select('p')
    ->leftJoin('OandPboBundle:Requests', 'r', 'WITH', 'r.partners = p.id')        
    ->where('p.date LIKE :date AND p.active = :active')
           ->setParameter('date', '%'.$year.'-'.$month.'%')
           ->setParameter('active', 1)

    ->orderBy('p.date', 'DESC')
    ->addOrderBy('p.id', 'DESC')
    ->getQuery()
    ->getResult();

And in my TWIG file I have

{% for partners in listPartners %}
            <tr>
                <td>{{ partners.id }}</td>
                <td>{{ partners.price }}</td>
            </tr>
{% endfor %}

And of course there is an error because they say there is no "price" field in "Partners" (of course I want to take it from "Quotations")

Is there a way to do that?

Aucun commentaire:

Enregistrer un commentaire