Querying for all instances of a superclass #6370
Replies: 2 comments 1 reply
-
I would be also interested into an answer for this. |
Beta Was this translation helpful? Give feedback.
-
try this code By changing shapes to []Shape{} (a slice of Shape), the db.Find(&shapes) query will fetch all rows from the "shapes" table, including instances of the subclasses (Circle and Rectangle). The result will be stored in the shapes slice, which can then be printed or used further in your code |
Beta Was this translation helpful? Give feedback.
-
In our current OpenAPI specification we have several subclasses of one base class, i.e. classes (or schemas) that share properties with another class and also add their own unique properties. We'd like in some cases to query just the specific subclasses (in my example below that's circles and rectangles), and in other cases to query over all superclass instances (shapes in my example), which should then include all instances of subclasses. Would it be a good approach to create a view (using Migrator#CreateView) every time we have such a use case?
Beta Was this translation helpful? Give feedback.
All reactions