typeorm-model-generator icon indicating copy to clipboard operation
typeorm-model-generator copied to clipboard

Support for inheritance feature in Postgres

Open acisser opened this issue 4 years ago • 4 comments

The model generation for Postgres engine is not working when data model contains inheritance Postgres feature.

The cli is raising the following error.

Table Person has no PK Error occurred in typeorm-model-generator.

acisser avatar Oct 22 '20 21:10 acisser

As I understand with this feature same data is accessible(and modifiable) in multiple tables. Unless ORM support such feature directly it's not wise to use them together(at least in any automated way). You can end up with weird ORM errors or in worst case in data corruption. Why? ORM often 'caches' some values so it would work faster(or detect model changes), if data is linked on the db side this may lead to unexpected consequences like data corruption. As far as I know typeorm doesn't support inheritance on database level(only on typescript model level), so support for such tables will have to way until typeorm can understand that kind of relation.

Kononnable avatar Oct 27 '20 18:10 Kononnable

The inheritance feature for Postgres is just for modeling purposes since it's actually not using a common table for sharing those common columns. It will append that list of columns declared in the base table declaration to each of the actual physical tables inheriting from it.

After checking this issue twice. I realized that even the console raises the mentioned error "Table Person has no PK", the generation is working well for my model, just needed to manually remove Person generated entity that shouldn't be actually converted to an entity since it's not a physical table.

acisser avatar Nov 07 '20 22:11 acisser

So perhaps the issue is just about skipping the base declaration table from on entity generation and that's all. Everything else is fine.

acisser avatar Nov 07 '20 22:11 acisser

Skimmed through docs and it looked like sharing data and schema. If it's just about sharing schema and functionality mostly works it should be much easier to implement.

Kononnable avatar Nov 18 '20 22:11 Kononnable