Hi everybody,
i am fairly new to scala at all, but it caught my interest while i digged into the play framework.
Offering anorm as sql layer for play in scala did bother my, because i dont like writing my own queries anymore, looking for alternatives it seemed to me that circumflex-orm fits much better for my programming needs.
Now i try to integrate this into my play 2 project, but only successfull to the half. I was able to retrieve records from my database with the following function:
object Task extends Task with Table[Long, Task] {
def findById(id: Long): Option[Task] = (this AS "t").map(t =>
SELECT(t.*).FROM(t).WHERE(
t.id EQ id).unique)
}
Debbuging into my code i could see that the retrieval did work and the values were set accordingly.
But i just cannot figure out how to:
1. print the value from my class variables,
val task = Task.findById(1)
println(
task.name)
returns "
task.name" instead the value of
task.nameand
2. how to store something in database. I read the docs and according to them it should suffice to call the .save() function on a task, but doing
val task = new Taks("foo", "bar")
println(task.save())
returns "1" what shouldnt be, as there are already records in the DB and the primary key "1" is already used.
This is my class:
class Task extends Record[Long, Task] with IdentityGenerator[Long, Task] {
def this(name: String, description: String) = {
this()
this.name := name
this.description := description
}
val id = "id".BIGINT.NOT_NULL.AUTO_INCREMENT
val name = "name".VARCHAR(255).NOT_NULL
val description = "description".TEXT.NOT_NULL
val createdAt = "created_at".TIMESTAMP
val dueTo = "due_to".DATE
def PRIMARY_KEY = id
def relation = Task
}
Maybe if i knew more about scala i would find what is wrong, but i just cannot figure out how to do it right.
Any help is appreciated.
Thanks in Advance,
Sven