Skip to content
Advertisement

Easy Admin 3 Sort by date returns: create_date has no field or association named create_date

I’m trying to sort a field either by asc or desc date.

When i add the date field to my backend like so

DateTimeField::new('create_date', 'Create Date')->setSortable(true),

It works and it shows, but when i try to sort it i get the following error

[Semantical Error] line 0, col 62 near 'create_date ': Error: Class App\Entity\MyEntitiy has no field or association named create_date File:/home/wwwroot/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php Line: 63

Does anyone know why or how this happens ?

Thank you

EDIT: here is the field in MyEntity

   /**
     * @var DateTime|null
     *
     * @ORMColumn(name="create_date", type="datetime", nullable=true)
     */
    private $createDate;


 /**
 * Returns the CreateDate
 *
 * @return DateTime|null
 */
public function getCreateDate(): ?DateTime
{
    return $this->createDate;
}


/**
 * Sets the CreateDate
 *
 * @param DateTime|null $createDate
 * @return void
 */
public function setCreateDate(?DateTime $createDate)
{
    $this->createDate = $createDate;
}

Advertisement

Answer

You are not respecting the proper spelling for your property.

In your entity, the field is called createDate so you should use the same name when configuring your crud.

In your case :

DateTimeField::new('createDate', 'Create Date')->setSortable(true),
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement