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

Saturday, March 5, 2022

[FIXED] Or on symfony findOneBy

 March 05, 2022     doctrine, symfony     No comments   

Issue

Is possible to make a request by one filed or another using the orm on symfony

$user_test = $em->getRepository("AppBundle:UserTest")->findOneBy([
                    'hash' => $data->user_data->hash,
                    'code' => $data->user_data->hash],
                );

to get something like WHERE hash = 'foo' OR code = 'foo'


Solution

you have to define the method in the entity UserTest repository

// UserTestRepository.php

public function getUserTestByHashOrCode($hash, $code){
    return $this->createQueryBuilder('u')
        ->where('hash = :hash')
        ->orWhere('code = :code')
        ->setParameter('hash', $hash)
        ->setParameter('code', $code)
        ->getQuery()
        ->getOneOrNullResult();

and then

$user_test = $em->getRepository("AppBundle:UserTest")->getUserTestByHashOrCode($data->user_data->hash, $data->user_data->hash);


Answered By - user17180229
  • 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