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

Fetching entities with Composite Key Relations #8425

Closed

Conversation

michalbundyra
Copy link
Member

In our database design we are using entities with composite keys, and we are using composite keys relations between entities.

Let say we have the following entities with Primary Keys (PK):

  • Company (PK: company_code)
  • Customer (PK composite: company_code + customer_code)
  • Invoice (PK composite: company_code + invoice_code)

and the following relations in Invoice:

  • to Company (using company_code), not nullable
  • to Customer (using composite key company_code + customer_code), nullable

Now we have company_code (not null) but no customer_code (null).
We want to fetch Invoice entity, so that we get not null Company, and null Customer.

The problem is that loading Invoice with null Customer is not working - we are getting the following exception:

Exception: [Doctrine\Common\Proxy\Exception\OutOfBoundsException] Missing value for primary key code on Doctrine\Tests\Models\CompositeKeyRelations\CustomerClass

This PR provide a fix, to load the Customer in the described case.
The change is pretty simply, and no other tests are affected.

NOTE: Loading Company is not a problem as it is using relation on just one column (not a composite key). The description includes it just for completeness of the example.

@michalbundyra michalbundyra deleted the composite-key-relations branch March 28, 2023 21:19
@michalbundyra michalbundyra restored the composite-key-relations branch June 3, 2024 10:36
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 this pull request may close these issues.

1 participant