Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
anorm.Pk case is not handled by anyParameter method #905
I'm sending a pull request that fixes a little bug that happens when you want to pass a Pk object (stored as Any) as parameter to an SQL query:
val id : Any = Id(5)
This doesn't work properly because when the parameter is of type Any, it goes through the anyParameter method which does not handle anorm.Pk objects. When the parameter is of type Pk then it's fine cause it's handled by pkToStatement.
*Note: * This is my first pull request so I'm not sure if I have followed all the guidelines. The code compiles & doesn't seem to be breaking any of the tests.
I faced the problem when I was creating a generic insert method that takes a case class object & generates the SQL query for it (assuming that the fields will be named the same as the db columns).
So the getParams method gives me a Map[String,Any] and the insert method generates the query:
Please notice that here I use my own version of anyParameter (myAnyParameter) that has that extra case that handles the Pk.
It's not a big deal for me but it might save some time for others that might attempt to do something similar & they'll have to re-implement the anyParameter implicit method :)