How to represent in the database (android sqlite), one class that extends another? [closed]

1

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

example:

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

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

Football extends Exercise

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

Thank you for your help. Thank you.

    
asked by anonymous 08.05.2017 / 14:44

1 answer

0

I understand that soccer is a type of exercise, so it creates a "Soccer" table 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 from the Execicio table. For example:

Exercise (id, description, ...)

Soccer (id, exercise_id, duration, ...)

It may be necessary to enable constraints at the start of the database, to ensure that they work (it is not the default SQLite they are already active). For example, to do a CASCADE DELETE of a record of the Exercise table (when erasing an Exercise record, delete all Football records whose id in the foreign key is the same as the one erased in Exercise) the constraints must be enabled

When you need to retrieve correlated data from both tables, make an inner join between them or create a View with that inner join already ready to make it easier for you to use Content Providers (if that's your case ).

If you need more details, talk.

    
08.05.2017 / 19:03