How to represent in the database (android sqlite), a class that extends another?

Asked

Viewed 55 times

1

Hello, I’m working on android, I have a case where a table extends another.

example:

table Exercise -> String dataInicio, String description ...... etc

table Football -> String timeInicio, Int duration.... etc

Football extends Exercicio

and I do not know how to represent in the database (sqlite) the table "Football", since I have to have associated to the table "Football" the date of the table "Exercise".

I appreciate your help. Thank you.

1 answer

0

I am understanding that football is a type of exercise, so create a table "Football" and another "Exercise", each with its primary keys (id’s). In the Football table you must have a column (foreign key or FK) that will receive the primary key of the table Execisio. For example:

Exercise (id, description, ...)

Football (id, id_exercise, duration, ...)

You may need to enable constraints on database startup to ensure that they work (it is not standard for Sqlite they are already active). For example, to make a DELETE CASCADE from a record of the Exercise table (when deleting an Exercise record, delete all Football records whose id on the foreign key is the same as the one deleted in Exercise) the constraints have to be enabled

When you need to rescue correlated data from both tables, do an Inner Join (Futebol.id_exercicio = Exercicio.id) between them or create a View with this Inner Join ready to facilitate the use of Content Providers (if you are the case).

If you need more details, speak.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.