John Davidson

php - Shopware 6 - Using DAL to filter collections inside entities

0 comments
Message:


I want to get all Product Streams, which have at least one category. I am trying to do this:


$criteria = new Criteria();
$criteria->addAssociation('categories');
$criteria->addFilter(new NotFilter(
NotFilter::CONNECTION_OR,
[
new EqualsFilter('categories', null)
// Also tried this:
// new EqualsFilter('categories', ['id' => null])
]
));
$productStreams = $productStreamRepo->search($criteria, $this->context);

But this always results in the following error:


Call to a member function buildAccessor() on null

I always get this error, no matter what I do. Am I doing something wrong or how would I archive this?



My Answer:
>addAssociation('categories');_$criteria->addFilter(new NotFilter('categories', null));_$productStreamRepository = $this->container->get('product_stream.repository');_$productStreams = $productStreamRepository->search($criteria, $context);This code snippet creates a Criteria object and adds an association to the 'categories' entity. It then adds a filter to exclude any product streams that do not have any categories associated with them. Finally, it uses the product stream repository to search for product streams that meet the criteria and returns the result.

Rate this post

4 of 5 based on 1168 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us