We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

duplicated data in many to many relationship

Hi here,

I got a wired problem in my volt tempalte,

Category and Publication is 2 model with many to many relationship.

in my home page, I want list 5 categories' publication.

so, in my category controller:

   $categories = Category::find([
        'condition' => 'parent_id = NULL',
        'sort'      => 'id DESC',
        'limit'     => '5',
    ]);

and in my volt tempalte:

       {% for index,category in categories %}
            {% set link = url(['for':'category_page','category':category.getSlug()]) %}
            <section class="column-belt">
                <div class="header-main">
                    <a href="{{ link }}" class="more">More &gt;</a>
                    <div class="title">{{ category.getTitle() }}</div>
                </div>
                <ul class="gallery-3">
                    {% set publications = category.getPublications([
                        'conditions' : 'date <= NOW() ',
                        'order'      : 'date DESC',
                        'limit'      : 6
                    ]) %}
                    {% for publication in publications %}
                        {% set image = publication.getimage([
                                'id': publication.getId(),
                                'type': 'publication',
                                'width': 325,
                                'height': 183,
                                'strategy': 'a'
                        ]) %}
                        {% set link = url(['for':'publication', 'type':publication.getTypeSlug(), 'slug':publication.getSlug()]) %}
                        {% if image.isExists() %}{% set imageExists = true %}{% else %}{% set imageExists = false %}{% endif %}
                        <li>
                            {% if imageExists %}
                                <figure>
                                    <a class="image" href="{{ link }}">{{ image.imageHTML() }}</a>
                                </figure>
                            {% endif %}
                            <h2 class="heading2"><a href="{{ link }}">{{ publication.getTitle() }}</a></h2>
                        </li>
                    {% endfor %}
                </ul>
            </section>
        {% endfor %}

all the data is fine except the last category, there are some duplicated data which is showing twice.

Is there anybody can help with ?

Thanks !

$categories = Category::find([
        'condition' => 'parent_id = NULL',
        'sort'          => 'id DESC',
        'limit'         => '5',
        'group'     => 'id'
    ]);