Note that there are some explanatory texts on larger screens.

plurals
  1. POscala, play framework pattern type is incompatible with expected type
    primarykey
    data
    text
    <p>I have an issue with play framework and scala. My 2 Model class are below:</p> <p>In here UserProfile have one Foriegn key to User Account and MyFriend hav 2 Foriegn key 1. user_Id from user profile and friend_ID from Userprofile</p> <pre><code>case class UserProfile(id: Pk[Long] = NotAssigned, useraccountid: Option[Long], name: String, date_of_birth: Date, gender: String, image: String,status:String) object UserProfile{ val simple = { get[Pk[Long]]("user_profile.id") ~ get[Option[Long]]("user_profile.user_account_id") ~ get[String]("user_profile.name") ~ get[Date]("user_profile.date_of_birth") ~ get[String]("user_profile.gender") ~ get[String]("user_profile.image") ~ get[String]("user_profile.status") map { case id ~ user_account_id ~ name ~ date_of_birth ~ gender ~ image ~ status =&gt; UserProfile(id, user_account_id, name, date_of_birth, gender, image,status ) } } /** * Parse a userProfile from a MyFriend */ val withMyFriend =UserProfile.simple ~ (MyFriend.simple ?) map{ case userprofile ~ myfriend =&gt; (userprofile, myfriend) } /** * Register a new useraccount. * * @param useraccount. */ def insert(userProfile: UserProfile): Long = { DB.withConnection { implicit connection =&gt; SQL( """ insert into USER_PROFILE(USER_ACCOUNT_ID ,NAME,DATE_OF_BIRTH,GENDER,IMAGE,STATUS) values ( {user_account_id}, {name},{date_of_birth},{gender},{image},{status} ) """).on( 'user_account_id -&gt; userProfile.useraccountid.get, 'name -&gt; userProfile.name, 'date_of_birth -&gt; userProfile.date_of_birth, 'gender -&gt; userProfile.gender, 'image -&gt; userProfile.image, 'status -&gt; userProfile.status).executeUpdate() } } } </code></pre> <p>and</p> <pre><code>case class Post(id: Pk[Long]= NotAssigned, name:String, image:String, time:Date) object Post{ /** * Parse a Post from a Resultset */ val simple ={ get[Pk[Long]]("post.id") ~ get[String]("post.name")~ get[String]("post.image")~ get[Date]("post.time") map { case id ~ name ~ image ~ time=&gt; Post(id,name,image,time) } } /** * Parse a Post from a UserPost */ val withUserPost = Post.simple ~ (UserPost.simple ?) map{ case post ~ userpost =&gt; (post, userpost) } /** * Register a new post. * * @param post */ def insert(post: Post): Long = { DB.withConnection { implicit connection =&gt; SQL( """ insert into POST(NAME,IMAGE,TIME) values ( {name}, {image}, {time} ) """).on( 'name -&gt; post.name, 'image -&gt; post.image, 'time -&gt; post.time).executeUpdate() } } /** * Authonticate */ def authenticate(post: Post) = { DB.withConnection { implicit connection =&gt; val postFound = SQL( """ select * from POST where ID = (id} """).on( 'Id -&gt; post.id ).as(Post.simple.singleOpt) postFound } } }/** * Find Post With UserPost */ def userPost(post_id: Long) = { DB.withConnection { implicit connection =&gt; val userPost = SQL( """ select * from USER_POST where USER_POST_ID = {user_post_id} """).on( 'post_id -&gt; post_id).as(UserPost.simple.singleOpt) userPost } } </code></pre> <p>and here is my controller application:</p> <pre><code> /* Authenticate User For CreatePost*/ def authendticatePost = Action { implicit request =&gt; val alert: Alert = new Alert("", "") Common.setAlert(alert) createPostForm.bindFromRequest.fold( errors =&gt; BadRequest(views.html.createPost(errors, "There is some error")), post =&gt; { val postOpt = Post.authenticate(post) postOpt match { case None =&gt; val alert: Alert = new Alert("error", "Invalid Credentials") Common.setAlert(alert) val invalidCredentialsForm = Application.createPostForm.fill(Post(NotAssigned, post.name,post.image,post.time)) Ok(views.html.createPost(invalidCredentialsForm, "Invalid Credentials")) case Some(authpost: Post) =&gt; val userSession = request.session + ("Id" -&gt; authpost.id.toString) val createPostOpt = Post.userPost(authpost.id.get) createPostOpt match { case None =&gt; Ok(views.html.createPost(Application.createPostForm, "")).withSession(userSession) case Some(postFound: Post) =&gt; val createPostFormWithDetails = Application.createPostForm.fill(postFound) Ok(views.html.createPost(createPostFormWithDetails, "")).withSession(userSession) } } }) } /** Create Post*/ def createPost = Action { implicit request =&gt; val alert: Alert = new Alert("", "") Common.setAlert(alert) createPostForm.bindFromRequest.fold( errors =&gt; BadRequest(views.html.createPost(errors, "There is some error")), post =&gt; { Post.findByPostName(post.name).isEmpty match { case true =&gt; val createpost = Post(NotAssigned, post.name, post.image, post.time) Post.insert(createpost) Common.setAlert(alert) case false =&gt; val createpost = Post(NotAssigned, post.name, post.image, post.time) Post.insert(createpost) Common.setAlert(alert) } Results.Redirect("/post") }) } /** Redirect To post**/ def post = Action { implicit request =&gt; Ok(views.html.createPost(Application.createPostForm, "post")) } </code></pre> <p>and here is my routes:</p> <pre><code>POST /createPost controllers.Application.createPost GET /post controllers.Application.post </code></pre> <p>and I've got this error at compile time:</p> <pre><code> pattern type is incompatible with expected type; found : object None required: Unit : pattern type is incompatible with expected type; found : object None required: Unit Error occurred in an application involving default arguments. case None =&gt; ^ </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload