3

私は2つのエンティティとのOneToMany Relationshipを持っています:

1 つArticleは を持ち、Brand1 つBrandは多数を持ちArticlesます。私の Twig テンプレートで、Articlesそれぞれ5 つしか表示できないのはBrandなぜですか?

軽いクエリでそれを行うベストプラクティスは何ですか?

以下、私のコード:

{% for brand in colBrands %}

        {% for article in brand.articles %}

            <!-- Display only 5 results and stop -->

        {% endfor %}

{% endfor %}
4

1 に答える 1

3

スライス関数を使用します。

{% for brand in colBrands %}

        {% for article in brand.articles|slice(0, 5) %}

            <!-- Display only 5 results and stop -->

        {% endfor %}

{% endfor %}
于 2013-01-14T20:45:29.693 に答える