Reputation: 11
So I have a Item
model which has a Recipe
1:1 relation.
The Recipe (model) has an ObjectStorage containing 1:n CraftingMaterials (model) which are needed for crafting. Each CraftingMaterial has an amount
field and one relation to an Item (model)
Model Dump:
public function findItemUsedIn($item)
{
$query = $this->createQuery();
$query->matching(
$query->logicalAnd(
$query->in('material.item', [$item])
)
);
return $query->execute();
}
material.item
should be an ObjectStorage/Collection of Items.
So my goal is to filter if they contain the $item
to find all recipes which got this item assigned, but Extbase cannot find any results. The backend runs fine and I can assign all these items.
Somehow Extbase hang up materials being an object storage and tries to match the id of the material relation and not the item one level deeper.
Upvotes: 1
Views: 339
Reputation: 2592
I think you're confusing in()
and contains()
. As in() checks if a single-valued property exists in a multi-value operand, the latter method contains() checks if a multi-valued property contains a single-valued operand.
public function findItemUsedIn($item)
{
$query = $this->createQuery();
$query->matching(
$query->logicalAnd(
$query->contains('material', $item)
)
);
return $query->execute();
}
Upvotes: 0