I
I
Igor Katkov2015-10-16 10:48:24
symfony
Igor Katkov, 2015-10-16 10:48:24

How to write a dql query?

Hello!
I'm working on filters in the current project. There is such a structure.
d10869c0c225495186062a7a8b24f951.png
In the view there should be a list of option.name and its possible properties:

<ul>
    {% for option in options %}

        <li> {{ option.name }}
            <ul>
        {% for value in option.productsOptionValues  %}
            <li>
                <input type="checkbox" value="{{ value.value }}" name="filter[{{ option.name }}][{{ value.id }}]" {% if filter[option.name][value.id] is defined %} checked="checked" {% endif %} />
                {{ value.value }}
            </li>
        {% endfor %}
            </ul>
        </li>
    {% endfor %}
    </ul>

Here's a visual:
4fcf000fd3294992a808b3f1147a9ce6.png
I understand that you can get both the option and its distinct values ​​in one request. But I've been trying to do this for over an hour now and it just doesn't work. Actually what request in this case will be correct?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bears, 2015-10-16
@iKatkovJS

This can be done without dql:

$options = $this->getDoctrine()
      ->getRepository('AppBundle:Option')
      ->createQueryBuilder('o')
      ->select('o, v')
      ->join('o.values', 'v')
      ->getQuery()
      ->getResult();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question