我有三个学说2模型:
Person
- $id
- $schoolClasses (ArrayCollection, OneToMany PersonSchoolClass)
SchoolClass
- $id
PersonSchoolClass (ManyToOne SchoolClass)
- $id
- $schoolClass
- $person
- $active
在 myPerson::addSchoolClass(SchoolClass $schoolClass)
中,我想看看,如果SchoolClass
我的ArrayCollection<PersonSchoolClass>
.
我使用这段代码:
/**
* @param SchoolClass $schoolClass
* @return Person
*/
public function addSchoolClass(SchoolClass $schoolClass)
{
$criteria = Criteria::create()
->where(Criteria::expr()->eq("schoolClass.id", $schoolClass->getId()))
->setFirstResult(0)
->setMaxResults(1);
$t = $this->getSchoolClasses()->matching($criteria);
if (!$t) {
$t = new PersonSchoolClass();
$t->setPerson($this);
$t->setSchoolClass($schoolClass);
$this->getSchoolClasses()->add($schoolClass);
}
$t->setActive();
return $this;
}
$this->getSchoolClasses()->matching($criteria);
但我总是在(一分钟左右后进程被杀死)超时。
有人有想法吗?
非常感谢!