-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Cannot persist Read-Only association #141
Comments
Just to add some more context: That situation is quite common in many applications - we have the same table (and almost always the
I believe it would be helpful to be able to map that kind of relationship in Mikro-ORM, giving us the power to reuse the same table for different purposes. I know that ultimately this is due to bad data design, but nonetheless, is a pretty common scenario. EDIT: Pinpointing the issue, it's happening because MikroORM thinks the |
That is called single table inheritance: https://mikro-orm.io/docs/inheritance-mapping#single-table-inheritance Or maybe you have a table-per-type inheritance? That's unfortunately not supported. |
Hey, Martin, thanks for the reply! However, my use case is similar but isn't precisely table inheritance. There are two main differences:
Basically, it's not about inheritance, it's about a set of attributes and relationships being used in one context, while another set of attributes and relationships are used in a different context. As I've mentioned, imagine the example:
However, when we think about the
On the other hand, in the Company Management context, these are the attributes/relationships that matter:
So, the same user row is represented by a different set of attributes depending on the Bounded Context. That modeling strategy makes it easier to map only the necessary relationships and attributes for each context instead of reusing the same |
Describe the bug
TLDR
User
entity class with its schemaEmployee
entity class that shares some fields with theUser
(and resides in the same table)EmployeeDetail
class and entity with a One-To-One reference toEmployee
EmployeeDetail
entity, passing theemployee
as an attributeinsert into "user" ("id") values (default) returning "id" - null value in column "email" violates not-null constraint
Consider the following entity relationships:
Also, consider that we have an
Employee
entity that is not described in a table above. That happens because anEmployee
is a "sub-type" ofUser
, with the association with a company:EmployeeDetail
in the database, pointing to a reference ofEmployee
, Mikro-ORM throws an error:insert into "user" ("id") values (default) returning "id" - null value in column "email" violates not-null constraint
Stack trace
To Reproduce
Steps to reproduce the behavior:
yarn
docker compose up -d
yarn test
Expected behavior
A new
employee_detail
record should be created, given that we have the existinguser
in the database already.Additional context
You can look at the schemas in the repo linked, but here's both the
employee
andemployee_detail
schemas:Employee Schema
EmployeeDetail Schema:
Versions
The text was updated successfully, but these errors were encountered: