Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android-SQLite. One to many relation

My question is about working with sqlite and android.

I have this app which will record locations, and for each location the user will be able to add photos.

I have table for

locations(loc_id INTEGER, longitude REAL ,latitude REAL)

which works perfectly fine. But I need to create second one which is photos. The photos table will hold the path name of the photo as a TEXT. It must also have another field which refers to a specific location through the loc_id as a foreign key. The thing is I do not know how to link up those two.

Any help greatly appreciated thanks !

like image 997
Evdzhan Mustafa Avatar asked Jan 11 '23 12:01

Evdzhan Mustafa


1 Answers

CREATE TABLE locations(
  loc_id INTTEGER PRIMARY KEY, 
  longitude REAL,
  latitude REAL
);

CREATE TABLE photos(
  photo_id INTEGER PRIMARY KEY, 
  path TEXT, 
  fk_location INTEGER,
  FOREIGN KEY(fk_location) REFERENCES locations(loc_id)
);
like image 187
Simulant Avatar answered Jan 17 '23 08:01

Simulant