logo
down
shadow

Using doctrine findBy method


Using doctrine findBy method

By : user2949233
Date : November 16 2020, 06:23 AM
it fixes the issue Assuming the {author} parameter is the author's URI name or something (this is purely speculative), you have to fetch either the author object or the author ID from Doctrine first:
code :
$authorObj = $this->getDoctrine()->getManager()
    ->getRepository('AcmeBundle:Author')->findOneByName(urldecode($author));
$criteria = array('author' => $authorObj);
$criteria = array('author' => $author);
public function findPostBy(array $criteria)
{
    return $this->postRepository->findOneBy($criteria);
}


Share : facebook icon twitter icon
Method findBy() from Doctrine with DateTime

Method findBy() from Doctrine with DateTime


By : Hua Liu
Date : March 29 2020, 07:55 AM
around this issue findBy only search for exactly matches while you need greater then. In this case and also many other cases you can write your own query. You could use DQL or the queryBuilder. If you want to be able to re-use your query on other places then you could place your query in a repository class which is a good practice too. (check the docs). Now here you find a DQL example that you can place into your controller:
code :
$events = $this->getDoctrine()
        ->getManager()
        ->createQuery('SELECT e FROM AppBundle:Event e WHERE e.datestart > CURRENT_DATE()')
        ->getResult();
Doctrine findBy() calling method from entity

Doctrine findBy() calling method from entity


By : kimra
Date : March 29 2020, 07:55 AM
wish of those help findBy returns generally an ArrayCollection.
You should use findOneBy instead in order to target only one entity...
code :
$datat = $this->getDoctrine()  
   ->getRepository('AppBundle:users')  
   ->findOneBy(array('userId' => $userId));
setting method parameters dynamically from array (working with FindBy method in Doctrine)

setting method parameters dynamically from array (working with FindBy method in Doctrine)


By : Taylor T
Date : March 29 2020, 07:55 AM
Hope this helps If you need to send several (dynamic amount) of parameters to a method, you can use the call_user_func_array() like this:
code :
$arguments = [
    ['status'=>1],
    ['dateCreated'=>'DESC']
];

$queryInstance = Pluto::registry('doctrine')
     ->getRepository(\Application\Entity\Post::class);

$posts = call_user_func_array(
    [$queryInstance, 'findBy'], 
    $arguments
);
doctrine FindBy method with 'OR condition'?

doctrine FindBy method with 'OR condition'?


By : Mary Rose Benipayo
Date : March 29 2020, 07:55 AM
this will help Is it possible to use OR statement in Doctrine findBy() method? , I would just use DQL... Add a function like this to your repository:
Return array with Doctrine findBy method

Return array with Doctrine findBy method


By : Akhil Baby
Date : March 29 2020, 07:55 AM
I hope this helps . I am using the Doctrine findBy() method, but I want to get arrays returned instead of objects. This is my query: , craete a function into repository and then create a query builder
code :
/**
 * @return array
 */
public function getArray()
{
    return $this
        ->createQueryBuilder('x')
        ->orderBy('x.name', 'DESC')
        ->getQuery()
        ->getArrayResult();
}
$results = $this->getDoctrine()->getRepository('xBundle:x')->getArray();
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org