dwhjames / datomisca

Datomisca: a Scala API for Datomic
https://dwhjames.github.io/datomisca/
Apache License 2.0
130 stars 28 forks source link

Problem with SchemaType.instant and Cardinality.many #111

Closed GitsMcGee closed 10 years ago

GitsMcGee commented 10 years ago

I'm getting an error in my implicit reader when I create an implicit reader for an entity that has an attribute that is of type instant and cardinality many, which I'm pretty sure is a bug. Here's an example of a class with a singular date that works fine:

case class AppointmentRequest(title: String, proposedTime: Date)

object AppointmentRequest {

  object Schema {

    object ns {
      val appointmentRequest = new Namespace("appointmentRequest")
    }
    val title = Attribute(ns.appointmentRequest / "title", 
                          SchemaType.string, 
                          Cardinality.one)
    val proposedTime = Attribute(ns.appointmentRequest / "proposedTime", 
                                 SchemaType.instant, 
                                 Cardinality.one)
  }

  implicit val reader = (
    Schema.title.read[String] and
    Schema.proposedTime.read[java.util.Date]
  )(AppointmentRequest.apply _)
}

But if I change proposedTime to have a Cardinality.many...

case class AppointmentRequest(title: String, proposedTime: Set[Date])

object AppointmentRequest {

  object Schema {

    object ns {
      val appointmentRequest = new Namespace("appointmentRequest")
    }
    val title = Attribute(ns.appointmentRequest / "title", 
                          SchemaType.string, 
                          Cardinality.one)
    val proposedTime = Attribute(ns.appointmentRequest / "proposedTime",
                                 SchemaType.instant, 
                                 Cardinality.many)
  }

  implicit val reader = (
    Schema.title.read[String] and
    Schema.proposedTime.read[Date]
  )(AppointmentRequest.apply _)
}

It gives the following error:

[error] /.../AppointmentRequest.scala:29: There is no type-casting reader for type java.util.Date given an attribute with Datomic type java.util.Date and cardinality datomisca.Cardinality.many.type to type java.util.Date
[error]     Schema.proposedTime.read[Date]
[error]                             ^
dwhjames commented 10 years ago

give the following a try:

Schema.proposedTime.read[Set[Date]]
GitsMcGee commented 10 years ago

Well, now I feel ridiculous. ;)

Thanks for the quick reply.

dwhjames commented 10 years ago

no worries… I had to double check myself