lundi 6 avril 2015

Android SQLite composite primary key. Should I still implement BaseColumns

If I want to implement a many to many relationship in a two column SQLite table in Android like so:



CREATE TABLE favorites (
user_key,
bar_key,
FOREIGN KEY (user_key) references User(user_id),
FOREIGN KEY (bar_key) references Bar(bar_id),
PRIMARY KEY (column1, column2)
);


Should my Table classes in my Contract class still implement BaseColumns? In my mind, that would be an unnecessary primary key for this table



public static final class FavoritesEntry implements BaseColumns {
public static final Uri CONTENT_URI =
BASE_CONTENT_URI.buildUpon().appendPath(PATH_FAVORITES).build();

public static final String CONTENT_TYPE =
"vnd.android.cursor.dir/" + CONTENT_AUTHORITY + "/" + PATH_FAVORITES;
public static final String CONTENT_ITEM_TYPE =
"vnd.android.cursor.item/" + CONTENT_AUTHORITY + "/" + PATH_FAVORITES;

public static final String TABLE_NAME = "favorites";

public static final String COLUMN_USER_KEY = "user_key";
public static final String COLUMN_BAR_KEY = "bar_key";

public static Uri buildFavoritesUri(long id) {
return ContentUris.withAppendedId(CONTENT_URI, id);
}
}

Aucun commentaire:

Enregistrer un commentaire