api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.4k stars 856 forks source link

Filtering on Nested Properties doesn't works with mongo since 2.6 #4216

Closed bettinz closed 3 years ago

bettinz commented 3 years ago

Hello, I've updated Api-Platform to version 2.6.4 and since 2.6.x filter on nested properties doesn't work with doctrine and mongodb. I've a user entity with email property and events with user.email as filter. Other filters work as expected:

https://localhost/admin/events?page=1&itemsPerPage=50&mustSort=false&multiSort=false&user.email=user%40email.com&type=2

user.email is ignored type is working

Can you help me? Thanks.

simocheccoli commented 3 years ago

same issue here:

namespace App\Document;

use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\SearchFilter;
use App\Document\User;

/**
 * Class Event
 * @package App\Entity
 *
 * @ApiResource(
 *      attributes={
 *          "doctrine_mongodb"={
 *              "execute_options"={
 *                  "allowDiskUse"=true
 *              }
 *          },
 *          "order"={"dateTime": "DESC"},
 *          "pagination_client_items_per_page"=true
 *      },
 *      collectionOperations={
 *          "get" = {
 *              "openapi_context"={
 *                  "summary" = "Retrieve the list of all Events",
 *               },
 *          }
 *      },
 *      itemOperations={
 *          "get" = {
 *              "openapi_context"={
 *                  "summary" = "Retrieve the informations about a single Event",
 *              },
 *          }
 *      }
 * )
 *
 * @ApiFilter(DateFilter::class, properties={"dateTime"})
 * @ApiFilter(SearchFilter::class , properties={"client": "exact", "type": "exact", "code": "exact", "subCode": "exact", "title": "partial", "description": "partial" ,"user.email": "exact", "body": "partial"})
 *
 * @ODM\Document(collection="event")
 */
class Event
{
    const TYPE_INFO = 'info';
    const TYPE_ERROR = 'error';

    /**
     * @ODM\Id(name="_id", type="string")
     */
    private $id;

    /**
     * @ODM\Field
     */
    private $type;

    /**
     * @ODM\Field
     */
    private $code;

    /**
     * @ODM\Field
     */
    private $subCode;

    /**
     * @ODM\Field(type="collection")
     */
    private $body;

    /**
     * @ODM\Field
     */
    private $title;

    /**
     * @ODM\Field
     */
    private $description;

    /**
     *
     * @ODM\EmbedOne(targetDocument=User::class)
     */
    private $user;

    /**
     * @ODM\Field(type="date")
     */
    private $dateTime;

    /**
     * @var string
     * @ODM\Field()
     */
    private $client;

    /**
     * @ODM\Field
     */
    private $url;
....

<?php

namespace App\Document;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/**
 * @ODM\EmbeddedDocument
 *
 */
class User
{
    /** @ODM\Field(type="string") */
    private $firstName;

    /** @ODM\Field(type="string") */
    private $lastName;

    /** @ODM\Field(type="string") */
    private $email;

    /** @ODM\Field(type="string") */
    private $city;

    /** @ODM\Field(type="string") */
    private $address;

    /** @ODM\Field(type="string") */
    private $uuid;

    /** @ODM\Field(type="string") */
    private $company;

    /** @ODM\Field(type="string") */
    private $companyName;

    /** @ODM\Field(type="string") */
    private $phone;
....

from 2.6.4 user.email filter is not working!

simocheccoli commented 3 years ago

@alanpoulain are you sure that #4218 is related with this?

alanpoulain commented 3 years ago

This one is probably the fix: https://github.com/api-platform/core/pull/4221.

jdeniau commented 3 years ago

@alanpoulain hmm... I'm not sure, the fix only does fix the required filter validation, but not the fact that the doctrine filter does work after that.

It might be related to a similar change in 2.6 though?

simocheccoli commented 3 years ago

@jdeniau @alanpoulain any news?

jdeniau commented 3 years ago

@simocheccoli #4221 has been merged, can you try on the 2.6 branch if it did fix your issue ?

simocheccoli commented 3 years ago

@jdeniau @alanpoulain we can confirm that 2.6 branch fix this issue!

bettinz commented 3 years ago

Thank you @jdeniau @alanpoulain and @simocheccoli for the help 😎

simocheccoli commented 3 years ago

@jdeniau , @alanpoulain it seems that only version 5.* of mongodb is working... with mongo 4.2.3 this problem persists