我试图找出如何获取所有元素A,其中引用的元素B在特殊字段中具有值。
假设我有以下型号:
Person
id name active companyref
1 Pers1 1 1
1 Pers2 1 2
Company
id name filter
1 Comp1 1
1 Comp2 5
当我想要获得所有活跃的人时,我在我的存储库中执行以下操作:
function findAllActive() {
$query = $this->createQuery();
return $query->matching(
$query->equals('aktiv', 1)
)->execute();
}
现在我的问题是如何让refCompany得到filter = 5的所有人?
编辑:在我没有工作的答案后,我发布了我的确切案例:
这将起作用(我自己编写sql):
function findAllActiveForPaketstufe($paketstufe) {
$query = $this->createQuery();
$sql="SELECT p . *
FROM `tx_myext_domain_model_person` AS p
INNER JOIN tx_myext_domain_model_firma AS f ON f.uid = p.firma_ref
WHERE paketstufe =3";
return $query->matching(
$query->equals('aktiv', 1)
)->execute();
}
这不起作用(我只写了一半的sql):
function findAllActiveForPaketstufe($paketstufe) {
$query = $this->createQuery();
$sql="SELECT p . *
FROM `tx_myext_domain_model_person` AS p
INNER JOIN tx_myext_domain_model_firma AS f ON f.uid = p.firma_ref";
return $query->matching(
$query->logicalAnd(
$query->equals('aktiv', 1),
$query->equals('person.firmaref.paketstufe', intval($paketstufe))
)
)->execute();
}
我收到错误:致命错误:调用成员函数getParentKeyFieldName()
我还试过:
而不是“person.firmaref.paketstufe”我真正想要的是这样的东西(我根本不用写sql):
$query = $this->createQuery();
return $query->matching(
$query->locicalAnd(
$query->equals('companyref.filter', 5),
$query->equals('active', 1)
)
)->execute();
我怎样才能让它发挥作用?
答案 0 :(得分:1)
你可以这样做:
function findAllActive() {
$query = $this->createQuery();
return $query->matching(
$query->locicalAnd(
$query->equals('companyref.filter', 5),
$query->equals('active', 1)
)
)->execute();
}