Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query result type is not recognized if create the query builder on a trait #626

Open
IndraGunawan opened this issue Nov 11, 2024 · 3 comments

Comments

@IndraGunawan
Copy link

this commit 149cf71 makes the correct getResult return type if the method within the class, but it does not work if the query builder comes from a trait

trait MyTrait
{
	protected function getCustomQueryBuilder() {
		return $this->createQueryBuilder('t')
			->andWhere('t.enabled = true');
	}
}

class MyRepository
{
	use MyTrait;

	public function findBySomething(): array
	{
		$qb = $this->getCustomQueryBuilder()
			->andWhere('t.someInt = 1');
		return $qb->getQuery()->getResult();
	}

getting this error

 Method App\Repository\MyRepository::findBySomething() should return
         array<App\Entity\MyEntity> but returns mixed.
@janedbal
Copy link
Contributor

@ondrejmirtes The problem is that OtherMethodQueryBuilderParser do not find the method in the file. Any idea how to address that?

@ondrejmirtes
Copy link
Member

I don't know why it doesn't find that. Probably something related to traits :)

@janedbal
Copy link
Contributor

Here is why:

  • Declaring class is the trait user (class), not the trait
    • Thus, it parses the file where the method is not present
    • But we cannot parse trait file as those make sense only when analysed within a class.

Failing test: #627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants