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

Entity STI not working in OneHasOne relationship #714

Closed
martenb opened this issue Dec 18, 2024 · 12 comments · Fixed by #717
Closed

Entity STI not working in OneHasOne relationship #714

martenb opened this issue Dec 18, 2024 · 12 comments · Fixed by #717
Assignees

Comments

@martenb
Copy link
Contributor

martenb commented Dec 18, 2024

Describe the bug
We are using same personal_data table for admins and users. So, we have 1:1 relationship between them. This feature stops working in v5.

To Reproduce
If you need, i can try to create test with failure.

Versions::

  • Orm: 5.0.1
  • Dbal: 5.0
@martenb martenb added the bug label Dec 18, 2024
@hrach
Copy link
Member

hrach commented Dec 18, 2024

I don't necessarily need a test case, but the error would be valuable.

@martenb
Copy link
Contributor Author

martenb commented Dec 18, 2024

Image

@hrach
Copy link
Member

hrach commented Dec 18, 2024

Could you please provide the class/STI hierarchy?

@hrach hrach self-assigned this Dec 19, 2024
@hrach
Copy link
Member

hrach commented Dec 19, 2024

@martenb 🙏

@martenb
Copy link
Contributor Author

martenb commented Dec 20, 2024

Ok, here is "minimal" code sample. Works properly with v4...

/**
 * @property-read int $id {primary}
 * @property AdminPersonalData $personalData {1:1 AdminPersonalData::$admin, cascade=[persist, remove]}
 */
class Admin extends Entity
/**
 * @property Admin $admin {1:1 Admin::$personalData, isMain=true}
 */
class AdminPersonalData extends PersonalData
/**
 * @property-read int $id {primary}
 */
abstract class PersonalData extends Entity
class PersonalDataRepository extends Repository
{

	public static function getEntityClassNames(): array
	{
		return [PersonalData::class, AdminPersonalData::class, UserPersonalData::class];
	}

	public function getEntityClassName(array $data): string
	{
		return isset($data['admin'])
			? AdminPersonalData::class
			: UserPersonalData::class;
	}

}

@hrach
Copy link
Member

hrach commented Dec 20, 2024

Thanks a lot.

@hrach
Copy link
Member

hrach commented Dec 20, 2024

@martenb Hi, I tried to reproduce this but sadly I'm unable to do so. My test cases include a query from both sides of the the relationship.

So to debug, please:

  • do you see a correct SQL?
  • does running the SQL yourself return the wanted data?
  • at HasOne:181 - could you dump($this->value); to see if there is something?

@hrach
Copy link
Member

hrach commented Jan 2, 2025

@martenb could you please help me with reproduction? thx.

@martenb
Copy link
Contributor Author

martenb commented Jan 3, 2025 via email

@hrach
Copy link
Member

hrach commented Jan 4, 2025

Thx a lot for the report, fixed; you may test it by updating to v5.0 branch.

@martenb
Copy link
Contributor Author

martenb commented Jan 6, 2025

Looks ok, thx

@hrach
Copy link
Member

hrach commented Jan 6, 2025

Thx, released as https://github.com/nextras/orm/releases/tag/v5.0.1.

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

Successfully merging a pull request may close this issue.

2 participants