Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find columns using multiple values in Doctrine and Symfony2?

image I have the following database structure

class voters
{
    protected $voterid;
    protected $imageid;
    protected $action;
}

// $voterid = is the current voter
// $imageid = is the id of the voted image
// $action = is upvote/downvote,delete

what happens if I want to look for several items at once, to check if a column exists, something like

$dummy = findOneBy('voterid'=>1,'imageid'=>2,action=>"upvote");

if($dummy)
{
   //column exists!
}

Is this possible?

like image 354
Gabriel ThaKid Avatar asked Feb 03 '14 09:02

Gabriel ThaKid


2 Answers

See Databases and Doctrine

If you want to retrieve a product, regarding some properties, you just have to use the method findOneBy with as parameters an array :

$product = $repository->findOneBy(array('name' => 'foo', 'price' => 19.99));
like image 155
Laurent W. Avatar answered Nov 07 '22 15:11

Laurent W.


You must pass all values as array like this:

$dummy = $this->getDoctrine()->getRepository("AcmeDemoBundle:User")->findOneBy(array(
    'voterid'=>1,
    'imageid'=>2,
    'action'=>'upvote',
));

if($dummy)
{
   //column exists!
}

Where key of array is a column name, value is a value in this column.

NOTE: AcmeDemoBundle:User - is your entity

like image 40
Victor Bocharsky Avatar answered Nov 07 '22 15:11

Victor Bocharsky