我有以下Task
类/实体:
/**
* @ORM\Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"task" = "Task", "upload" = "UploadTask", "follow" = "FollowTask", "like" = "LikeTask", "comment" = "CommentTask", "scape" = "ScrapeTask"})
*/
class Task
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="PlayBot\UserBundle\Entity\User", inversedBy="task")
* @ORM\JoinColumn(name="account_id", referencedColumnName="id")
*/
protected $account;
/**
* @ORM\ManyToOne(targetEntity="PlayBot\PlayBundle\Entity\Interval", inversedBy="task")
* @ORM\JoinColumn(name="interval_id", referencedColumnName="id", nullable=true)
*/
protected $interval = NULL;
}
以及以下Interval
类:
/**
* @ORM\Entity
* @ORM\Table(name="interval")
*/
class Interval
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="PlayBot\PlayBundle\Entity\Task", mappedBy="interval")
*/
protected $task;
/**
* @ORM\Column(type="integer")
*/
protected $interval;
}
我想找到Task
Interval
设置为$interval
的所有20
。
我该怎么办?
答案 0 :(得分:1)
使用doctrine查询构建器。
$tasks = $this->em->getRepository('Task')->createQueryBuilder('t')
->join('t.interval', 'i')
->where('i.interval = :interval')
->setParameter('interval', 20)
->getQuery()
->getResult();