[英]Is it possible to find columns using multiple values in Doctrine and Symfony2?
image I have the following database structure image我有以下数据库结构
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? 这可能吗?
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 : 如果要检索产品,关于某些属性,您只需使用方法findOneBy
作为参数作为数组:
$product = $repository->findOneBy(array('name' => 'foo', 'price' => 19.99));
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. 如果数组的键是列名,则value是此列中的值。
NOTE: AcmeDemoBundle:User
- is your entity 注意: AcmeDemoBundle:User
- 是您的实体
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.