Browse Source

Collect taboo words using id instead of word

Thomas Dy 10 năm trước cách đây
mục cha
commit
365ad0d147
1 tập tin đã thay đổi với 4 bổ sung4 xóa
  1. 4 4
      app/models/Card.scala

+ 4 - 4
app/models/Card.scala

@@ -33,17 +33,17 @@ object Card {
 
   def list() = DB.withConnection { implicit c =>
     val list = SQL("""
-      select words.word as word, taboo.word as taboo
+      select words.id as id, words.word as word, taboo.word as taboo
       from words left join taboo on word_id = words.id
     """)
-    .list(str("word") ~ str("taboo") map flatten)
+    .list(int("id") ~ str("word") ~ str("taboo") map flatten)
 
     mapToCard(list)
   }
 
-  def mapToCard(seq: Seq[(String, String)]) = {
+  def mapToCard(seq: Seq[(Int, String, String)]) = {
     seq.groupBy(_._1).map {
-      case (word, taboos) => Card(word, taboos.map(_._2).toSet)
+      case (id, taboos) => Card(taboos.map(_._2).head, taboos.map(_._3).toSet)
     }.toList
   }
 }