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

Condition over table (without ->id) is not working #574

Open
hrach opened this issue Apr 20, 2022 · 3 comments
Open

Condition over table (without ->id) is not working #574

hrach opened this issue Apr 20, 2022 · 3 comments
Assignees

Comments

@hrach
Copy link
Member

hrach commented Apr 20, 2022

To Reproduce

/**
 * @property-read string         $id        {primary}
 * @property AlarmDeparture|null $departure {1:1 AlarmDeparture::$alarm}
 */
final class Alarm extends Entity
{

}

/**
 * @property-read string $id    {primary}
 * @property-read Alarm  $alarm {1:1 Alarm::$departure, isMain=true}
 */
final class AlarmDeparture extends Entity
{

}

$alarmRepository->findBy([
	'departure!=' => null,
])->fetchAll();

Produces

Nextras\Dbal\Drivers\Exception\QueryException: ERROR:  column alarms . departure does not exist
LINE 1: ...'alarms' .* FROM 'app' . 'alarms' as 'alarms' WHERE('alarms' . "...

Expected behavior
It works.

Workaround

$alarmRepository->findBy([
	'departure->id!=' => null,
])->fetchAll();
@hrach hrach added the bug label Apr 20, 2022
@hrach hrach removed the bug label Oct 1, 2024
@hrach hrach added this to the v5.0 milestone Oct 11, 2024
@hrach hrach self-assigned this Oct 11, 2024
@hrach hrach removed this from the v5.0 milestone Oct 11, 2024
@hrach
Copy link
Member Author

hrach commented Oct 11, 2024

Current status:

It is not working on the non-main side. The main side works due to the implementation detail that the property is mapped to the actual column (alarm_id) and then the comparison works.

Since we do not do any optimization when alarm->id would be optimized to alarm_id comparison without a join, I am not super sure that what the future is here - if we want to support the shortcut as it is; expand its behavior to auto-optimize and/or support it on the non-main side.

Also, the Orm IntelliJ plugin auto-adds -> after picking "departure".

@hrach
Copy link
Member Author

hrach commented Oct 11, 2024

I am marking it as a feature request.

@hrach hrach changed the title Condition over table (without its column/PK) is not working Condition over table (without ->id) is not working Oct 11, 2024
@hrach
Copy link
Member Author

hrach commented Oct 12, 2024

testcase:

	public function testFilterAutomaticallyById(): void
	{
		$ean = new Ean();
		$ean->code = '1234';
		$ean->book = $this->orm->books->getByIdChecked(1);
		$this->orm->eans->persistAndFlush($ean);
		$eanId = $ean->id;
		$this->orm->clear();

		$ean = $this->orm->books->findBy(['ean' => $eanId])->fetch();
		Assert::notNull($ean);

		$book = $this->orm->eans->findBy(['book' => 1])->fetch(); // failure
		Assert::notNull($book);
	}

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

1 participant