How to handle anorm's Pk deprecation
Asked Answered
H

2

7

Since version 2.3.0 of the anorm library of play framework, the trait Pk is deprecated and it suggests the usage of its subclasses Id and NotAssigned (documentation).

But what if we have a variable that can take either an Id or a NotAssiged? Specifically, in my code I have a class Person(id: Pk[Long], name: String). Using Pk as the type of id, I can create new users like Person(NotAssigned, "kostas") or get existing from my db Person(Id(3), "kostas").

How can I migrate my code to not use the deprecated Pk trait, but hold the same functionality?

Herzen answered 12/6, 2014 at 19:15 Comment(0)
C
7

Pk[A] is the same as Option[A] by structure, where Id[A](value) corresponds to Some[A](value), and NotAssigned corresponds to None.

So the recommended migration would be to use Option[Long], instead. I don't really understand the developers' decision to deprecate Pk[A] though, but not Id[A] and NotAssigned, as both are essentially useless without it. Nonetheless, Option will function the same for you, and anorm handles it just the same.

Capet answered 12/6, 2014 at 19:22 Comment(0)
M
3

Migration notes are being added about this deprecation: https://github.com/playframework/playframework/pull/3029/files . Previous answer is right about Option use.

Best

Manganin answered 13/6, 2014 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.