Issue
I use EasyAdminBundle 2x and Symfony 4.4. I have two entities:
UserCase
entity:
/**
* @ORM\OneToMany(targetEntity="App\Entity\MyReports", mappedBy="userCase")
*/
protected $myReports;
And MyReports
entity:
/**
* @ORM\ManyToOne(targetEntity="App\ORM\Entity\UserCase", inversedBy="myReports", cascade={"persist"})
* @ORM\JoinColumn(name="user_case", referencedColumnName="id", onDelete="CASCADE")
* @Serializer\Exclude()
*/
protected $userCase;
/**
* @var DateTime
*
* @ORM\Column(name="verified_date", type="datetime", nullable = true)
*/
protected $verifiedDate;
In the list view of UserCase, I would like to show the verifiedDate
of the latest MyReports that UserCase relation with. Something like that:
easy_admin:
entities:
UserCase:
class: App\ORM\Entity\UserCase
list:
fields:
- { property: 'myReports.last.verifiedDate'}
How could I do it?
Solution
Please useEasyAdmin
Virtual Properties:
- add
verifiedDate
property toeasy_admin
config file (instead of'myReports.last.verifiedDate'
); - add new public method to
UseCase
entity:getVerifiedDate
with your logic of selecting last record with proper date;
Also: I'd recommend adding extra property to UserCase
e.g. verifiedDate
that will be updated instead of fetching last record for each row in grid.
Answered By - Kamil Adryjanek Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.