X-Git-Url: http://git.shiar.nl/sheet.git/blobdiff_plain/ea5b27f93e87b819504b4cbcdf5aa7e47cff0175..9ddf2e9a6173fcb1649ab9dd72ded3896195c83f:/tools/word.pg.sql

diff --git a/tools/word.pg.sql b/tools/word.pg.sql
index 1bc5dff..7aacfa8 100644
--- a/tools/word.pg.sql
+++ b/tools/word.pg.sql
@@ -48,6 +48,23 @@ CREATE OR REPLACE FUNCTION exportform(word) RETURNS text AS $$
 	);
 $$ LANGUAGE SQL IMMUTABLE;
 
+CREATE OR REPLACE VIEW _word_ref AS
+	SELECT
+		r.form, r.alt, r.lang,
+		coalesce(r.cat,     w.cat    ) cat, --TODO translate w?
+		coalesce(r.ref,     r.id     ) "ref",
+		coalesce(r.prio,    w.prio   ) prio,
+		coalesce(r.source,  w.source ) source,
+		coalesce(r.thumb,   w.thumb  ) thumb,
+		coalesce(r.wptitle, w.wptitle) wptitle,
+		r.created, r.updated,
+		CASE WHEN r.source IS NULL THEN w.id ELSE r.id END id, -- image id
+		coalesce(r.cover,   w.cover  ) cover,
+		coalesce(r.grade,   w.grade  ) grade,
+		r.creator
+	FROM word r
+	LEFT JOIN word w ON w.id = r.ref;
+
 CREATE OR REPLACE VIEW _cat_words AS
 	SELECT exportform(word.*) form, sub.*, word.lang, word.ref
 	FROM word RIGHT JOIN (
