vapor / fluent-kit

Swift ORM (queries, models, and relations) for NoSQL and SQL databases
MIT License
211 stars 116 forks source link

Support table inheritance #60

Closed fwgreen closed 4 years ago

fwgreen commented 5 years ago

I'm opening a separate issue from (https://github.com/vapor/fluent-kit/issues/46) as it isn't clear to me if the lack of model inheritance precludes having table inheritance as a feature.

Let's say I have a table of galaxies:

+----+------------------------+-------------+
| id |          name          | GALAXY_TYPE |
+----+------------------------+-------------+
|  1 | M100                   | SPIRAL      |
|  2 | Large Magellanic Cloud | IRREGULAR   |
|  3 | M87                    | ELLIPTICAL  |
+----+------------------------+-------------+

Is it possible to implement table inheritance in Fluent without model inheritance?

tanner0101 commented 4 years ago

@fwgreen hmm not sure what you mean by this one. Could you elaborate?

fwgreen commented 4 years ago

@tanner0101 I was hoping for a way to have Single Table Inheritance, similar to JPA or ActiveRecord, by somehow using the ORM to get around the issue of models needing to be final.

tanner0101 commented 4 years ago

Hmm ok. I'm not very familiar with that. As long as the table looks like a normal one to the model everything should work fine. You can use custom SQL commands in the migrations to create whatever type of DB structure you want. If you find something in FluentKit that could be changed or added to make this easier let me know.