John Davidson

php - Using Array Entity in Doctrine Query Builder

0 comments
Message:




How are you?

I created an array entity.



   /**
* @Groups({"event_rating_question", "portal"})
*
* @ORM\Column(type="json", nullable=true)
*/
private ?array $eventTypeIds = [];

In the repository, I want to get the results if the request parameter is in that array entity.

So I created the repository function like:


public function findQuestionsByEventType(int $eventTypeId)
{
$queryBuilder = $this->createQueryBuilder('item')
->andWhere(':eventTypeId MEMBER OF item.eventTypeIds')
->setParameter('eventTypeId', $eventTypeId)
->orderBy('item.sortOrder', 'ASC');

return $queryBuilder->getQuery()->getResult();
}

But I have an error like below:
"Exception: [Semantical Error] line 0, col 88 near 'eventTypeIds': Error: Invalid PathExpression. Must be a CollectionValuedAssociationField."

If someone knows how to fix it, please let me know.

Thanks.



My Answer:
doctrine_query_builder, array_entity})_ */_ private $arrayEntity;_ /**_ * @return ArrayCollection|ArrayEntity[]_ */_ public function getArrayEntity(): ArrayCollection_ {_ return $this->arrayEntity;_ }_ /**_ * @param ArrayCollection|ArrayEntity[] $arrayEntity_ */_ public function setArrayEntity(ArrayCollection $arrayEntity): void_ {_ $this->arrayEntity = $arrayEntity;_ }_}

Rate this post

3 of 5 based on 9295 votes

Comments




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