How to get the first entity from linked entity

Viewed 34139

I have the

Class User  {

@OneToMany
    private $profiles
}

Now I have the $user entity in my controller but I also want the first or last profile based on date. How can I achieve this?

I have the method getProfiles() but I think that will return the array collection.

2 Answers

You can easily get the first one like that :

$first = $this->get('doctrine.manager')->getRepository(MyEntity::class)->findOneBy([]);
Related