ignored(NotAssigned:Pk[Long]), "name" -> nonEmptyText, "introduced" -> optional(date("yyyy-MM-dd")), "discon" /> ignored(NotAssigned:Pk[Long]), "name" -> nonEmptyText, "introduced" -> optional(date("yyyy-MM-dd")), "discon" /> ignored(NotAssigned:Pk[Long]), "name" -> nonEmptyText, "introduced" -> optional(date("yyyy-MM-dd")), "discon"/>

too many arguments for method mapping: (apply: (String, String, String) => R)(unapply: R => Option[(String, String, String)])play.api.data.Mapping[R]

3.1k views Asked by At
val computerForm = Form(
    mapping(
        "id" -> ignored(NotAssigned:Pk[Long]),
        "name" -> nonEmptyText,
        "introduced" -> optional(date("yyyy-MM-dd")),
        "discontinued" -> optional(date("yyyy-MM-dd")),
        "company" -> optional(longNumber)
    )(Computer.apply)(Computer.unapply)
)

this code giving me the error too many arguments for method mapping:

(apply: (String, String, String) => R)(unapply: R => Option[(String, String, String)])play.api.data.Mapping[R]..please solve this issue"
1

There are 1 answers

0
Edmondo On

Let's go in order, from Play2 Scaladoc. The Form method you are calling is Form.apply

Form scaladoc

def apply[T](mapping: (String, Mapping[T])): Form[T]

so your mapping(smth) should return a (String,Mapping[T]). The mapping method is instead defined in the object Forms

Forms Scaladoc

Forms.mapping is an overloaded method with multiple available signatures, let's look at one

def
mapping[R, A1, A2, A3, A4](a1: (String, Mapping[A1]), a2: (String, Mapping[A2]), a3: (String, Mapping[A3]), a4: (String, Mapping[A4]))(apply: (A1, A2, A3, A4) ⇒ R)(unapply: (R) ⇒ Option[(A1, A2, A3, A4)]): Mapping[R]

So this method takes a first list of parameters (a1,a2,a3,a4) each of type (String,Mapping[Aindex]), one another list of parameter containing a single parameter apply: (A1, A2, A3, A4) ⇒ R , and a last parameter list containing a single parameter unapply: (R) ⇒ Option[(A1, A2, A3, A4)]

In general, for all overloaded version of mapping, the signature impose such that apply / unapply should have the signature corresponding a tupled version of the first list of parameter.

What is happening here, is that through -> you are creating 5 (String,Mappings[Asomething]) tuples, while your apply/unapply has only 3 arguments