Symfony - How to add a new search filter from another entity? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Monday, March 28, 2022

Symfony - How to add a new search filter from another entity?

I'm a beginner to Symfony, I working to a website with some data and have already some search filter (the entity is website) but I need to add a new filter but from another entity (from entity annonce and the field is date_disponibilite), the relation was ManyToOne but I changed to ManyToMany and I added a getter of annonce :

//Annonce.php

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Website", inversedBy="annonce")
     * @ORM\JoinTable(name="website_annonce")
     */
    protected $website; 

<some fields>
<some getters and setters>

    public function __toString()
    {
        return (string)$this->date_disponibilite ;
    }
//website.php
    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Annonce", mappedBy="website", cascade={"persist"})
     */
    private $annonce;

    /**
     * @return Collection|Annonce[]
     */
    public function getAnnonce(): Collection
    {
        return $this->annonce;
    }

I added correctly the field to the form and in the filter function but when I send the search request I have this error :

Object of class Doctrine\ORM\PersistentCollection could not be converted to string

in src/Service/ElasticaService.php (line 188)

    187    if ($website && $website->getAnnonce()) {
    188        $where[] = "date_disponibilite='".$website->getAnnonce()."'";
    199    }

I added a func toString to my Annonce entity but the issue still persist, I don't know how can I fix my it, some one have an idea to solve my issue ?

thanks in advance



source https://stackoverflow.com/questions/71639031/symfony-how-to-add-a-new-search-filter-from-another-entity

No comments:

Post a Comment