Re: [2.1-RC3 Scala] Noob question sorry - How to set a default Seq[Seo] if there is no result from databases?

26 views
Skip to first unread message
Message has been deleted

Sarvesh Kumar Singh

unread,
Feb 4, 2013, 7:57:10 AM2/4/13
to play-fr...@googlegroups.com
def getSeoForSor(page: String): Seq[Seo] = {
    getSeo match {
        case Nil => Seq( Seo("my default seo") )
        case a :: _ => getSeo
    }
}

Julien L.

unread,
Feb 4, 2013, 8:07:57 AM2/4/13
to play-fr...@googlegroups.com
Sarvesh Kumar Singh, you make 2 DB call here, no?

I would have written something like that: 

getSeo match { 
  case Nil => Seq(/* your default seo*/) 
  case result => result 
Message has been deleted
Message has been deleted
Message has been deleted

Sarvesh Kumar Singh

unread,
Feb 4, 2013, 8:19:48 AM2/4/13
to play-fr...@googlegroups.com
In that case.. I think answer by Jullen is better

def getSeoForSor(page: String): Seq[Seo] = {
    getSeo(page) match {
        case Nil => Seq(/* your default seo*/)
        case result => result
    }
}  

On Monday, 4 February 2013 18:39:13 UTC+5:30, Alex wrote:
Hi Sarvesh

I get this when I add that def to my code

missing arguments for method getSeo in object Seo; follow this method with `_' if you want to treat it as a partially applied function

Julien L.

unread,
Feb 4, 2013, 8:23:42 AM2/4/13
to play-fr...@googlegroups.com
scala> Seq() match { 
  case Nil => Seq("default")
  case r => r 
}
res1: Seq[String] = List(default) // works

On Monday, February 4, 2013 2:17:01 PM UTC+1, Alex wrote:
Hi

Does not work

[IndexOutOfBoundsException: 0]

The Seq[Seo] is not getting fill with default values :(




On Monday, February 4, 2013 12:57:10 PM UTC, Sarvesh Kumar Singh wrote:
Message has been deleted
Message has been deleted

Julien L.

unread,
Feb 4, 2013, 8:48:55 AM2/4/13
to play-fr...@googlegroups.com
When it works in the Scala console but not in Play, you can be sure you have a Pebkac somewhere ;)

On Monday, February 4, 2013 2:36:14 PM UTC+1, Alex wrote:
THANKS Julien

I COULD CRY this works - thanks :) - I spent so many hours searching for this, I NEED to get better at Scala :)

THANKS


def getSeo(page : String) : Seq[Seo] = {
    DB.withConnection { implicit connection =>
      SQL("select * from seo where page = {page}").on('page -> page).as(Seo.pageseo *)
    }
    match {
      case Nil => Seq( Seo("London", "hello", "o"))
      case result => result
Reply all
Reply to author
Forward
Message has been deleted
0 new messages