From: APTX Date: Sun, 14 Jun 2015 10:27:56 +0000 (+0200) Subject: Add new FileEpisode table to DynamicModel. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=098eefeb5b6f44abbd2d11839c4234b45afa6d3a;p=localmylist.git Add new FileEpisode table to DynamicModel. This new table shows all files related to an episode and not just the files for which an episode is the main episode. To get all episodes a UNION is needed over file and file joined with file_episode_rel, but Dynamic Model's query builder does not support building such queries. The workaround is to do the UNION in a view and query it instead. File will be changed to what FileEpisode does in the future as it was File's intended behaviour. --- diff --git a/localmylist-management/tabs/dynamicmodeltab.cpp b/localmylist-management/tabs/dynamicmodeltab.cpp index 8503389..7dae96c 100644 --- a/localmylist-management/tabs/dynamicmodeltab.cpp +++ b/localmylist-management/tabs/dynamicmodeltab.cpp @@ -58,6 +58,7 @@ void DynamicModelTab::init() dataModel->registerDataType(new ColumnType); dataModel->registerDataType(new AnimeType); dataModel->registerDataType(new EpisodeType); + dataModel->registerDataType(new EpisodeFileType); dataModel->registerDataType(new FileType); dataModel->registerDataType(new FileLocationType); dataModel->registerDataType(new AnimeTitleType); @@ -66,8 +67,10 @@ void DynamicModelTab::init() dataModel->registerTypeRelation(new ForeignKeyRelation("anime", "file", "aid")); dataModel->registerTypeRelation(new ForeignKeyRelation("file", "anime", "aid")); dataModel->registerTypeRelation(new ForeignKeyRelation("episode", "file", "eid")); + dataModel->registerTypeRelation(new ForeignKeyRelation("episode", "episode_file", "eid", "meid")); dataModel->registerTypeRelation(new ForeignKeyRelation("file", "episode", "eid")); dataModel->registerTypeRelation(new ForeignKeyRelation("file", "file_location", "fid")); + dataModel->registerTypeRelation(new ForeignKeyRelation("episode_file", "file_location", "fid")); dynamicModelFilterModel = new DynamicModelFilterModel(this); diff --git a/localmylist/dynamicmodel/types.cpp b/localmylist/dynamicmodel/types.cpp index 2c4ea38..6376afa 100644 --- a/localmylist/dynamicmodel/types.cpp +++ b/localmylist/dynamicmodel/types.cpp @@ -482,6 +482,11 @@ void FileType::fillFileData(FileData &data, const SqlResultIteratorInterface &qu Database::readFileData(query, data.fileData, 1); } +QString EpisodeFileType::tableName() const +{ + return "episode_file"; +} + // ============================================================================================================= QString FileLocationType::tableName() const diff --git a/localmylist/dynamicmodel/types.h b/localmylist/dynamicmodel/types.h index 1a3c37c..8c7f04e 100644 --- a/localmylist/dynamicmodel/types.h +++ b/localmylist/dynamicmodel/types.h @@ -122,6 +122,12 @@ private: static void fillFileData(FileData &data, const SqlResultIteratorInterface &query); }; +class LOCALMYLISTSHARED_EXPORT EpisodeFileType : public FileType +{ + Q_OBJECT + QString tableName() const override; +}; + // ============================================================================================================= class LOCALMYLISTSHARED_EXPORT FileLocationType : public DataType diff --git a/localmylist/share/schema/schema.sql b/localmylist/share/schema/schema.sql index e55f568..f44ce9f 100644 --- a/localmylist/share/schema/schema.sql +++ b/localmylist/share/schema/schema.sql @@ -291,6 +291,12 @@ CREATE OR REPLACE VIEW rename_data AS JOIN quality q ON q.quality = f.quality JOIN file_location fl ON fl.fid = f.fid; +CREATE OR REPLACE VIEW episode_file AS + SELECT f.eid AS meid, f.* FROM file f + UNION + SELECT fer.eid AS meid, f.* FROM file f + JOIN file_episode_rel fer ON f.fid = fer.fid; + CREATE OR REPLACE RULE anime_update_rename_rule AS ON UPDATE TO anime WHERE old.aid = new.aid