How to deal with an abnormal Pk error

Since version 2.3.0 of the game structure anorm library, the Pk attribute is deprecated and suggests the use of its subclasses Id and NotAssigned ( documentation ).

But what if we have a variable that can accept either Id or NotAssiged ? In particular, in my code there is a class Person(id: Pk[Long], name: String) . Using Pk as an Id type, I can create new users such as Person(NotAssigned, "kostas") or get an existing one from my db Person(Id(3), "kostas") .

How can I port my code so as not to use the deprecated Pk trait, but stick to the same functionality?

+7
scala playframework anorm
source share
2 answers

Pk[A] matches Option[A] in structure, where Id[A](value) matches Some[A](value) , and NotAssigned matches None .

Therefore, the recommended migration will be to use Option[Long] . I really do not understand the decision of the developers to abandon Pk[A] , though, but not Id[A] and NotAssigned , since both of them are practically useless without it. However, Option will work the same for you, and anorm treats it the same way.

+7
source share

Migration notes are added about this deprecation: https://github.com/playframework/playframework/pull/3029/files . The previous answer is correct in using options.

The best

+3
source share

All Articles