PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 18, 2022

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

 February 18, 2022     easyadmin3, php, symfony     No comments   

Issue

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
     *
     * @ORM\Column(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;
}

Solution

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),


Answered By - Dylan Kas
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing