3

i have the next problem..

im using spray.http.DateTime, and my mapper is:

  implicit val JavaUtilDateTimeMapper =
    MappedColumnType.base[DateTime, Timestamp] (
      d => new Timestamp(d.clicks),
      d => spray.http.DateTime(d.getTime))


 case class EventosModelTable(
  id: Option[Long],
  idCliente: Option[Long],
  idPlan: Option[Long] = None,
  idServicio: Option[Long] = None,
  tipo: TipoEventos.Value,
  fechaInicio: DateTime,
  fechaFin: Option[DateTime]
) extends BaseModel

class EventosTabla(tag: Tag) extends Table[EventosModelTable](tag, "eventos") with BaseTabla{

  override def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
  def idCliente = column[Long]("id_cliente")
  def idPlan = column[Option[Long]]("id_plan")
  def idServicio = column[Option[Long]]("id_servicio")
  def tipo = column[TipoEventos.Value]("tipo_evento")
  def fechaInicio = column[DateTime]("fecha_inicio")
  def fechaFin = column[Option[DateTime]]("fecha_fin")

  def * = (id.?,idCliente.?,idPlan,idServicio,tipo,fechaInicio,fechaFin) <> (EventosModelTable.tupled, EventosModelTable.unapply _)

  def cliente = foreignKey("cliente",idCliente,TableQuery[ClientesTabla])(_.id)
  def plan = foreignKey("plan",idPlan,TableQuery[PlanesTabla])(_.id)
}

then.. i need find Event's where fechaFin are Null or fechaFin> DateTime.now... but the problem is that fechaFin can be Null then is a Option value, and i cant compare with a DateTime.now.. the compile error is that Some[DateTime] dont have > method.

I will appreciate any help

the query is as follows..

def getAltasBajas(id : Long) : DBIOAction[Seq[EventosModelTable],NoStream,Effect.All] = {

      val q = for {
        altasBajas <- tabla.filter(_.idCliente === id)
            if altasBajas.fechaFin.isEmpty || (altasBajas.fechaFin.isDefined && (altasBajas.fechaFin)<(DateTime.now))
      }yield altasBajas

      q.result
    }

1 Answers1

1

I found this answer that would indicate that your implementation should work (at least as far as I can see) or you could try

val q = for {
  altasBajas <- tabla.filter(_.idCliente === id)
  if !altasBajas.fechaFin.isNull || altasBajas.fechaFin < DateTime.now
} yield altasBajas
Community
  • 1
  • 1
Sascha Kolberg
  • 7,092
  • 1
  • 31
  • 37
  • Hi Sascha, this dont work... forall is not a member method of altasBajas.fechaFin – Juan Pablo Vittori Jul 23 '15 at 13:33
  • Yeah, that's the part where I said "I am not a Slick expert" ;). However, according to [link](http://stackoverflow.com/questions/17554304/slick-and-filtering-by-option-columns) your implementation or `if !altasBajas.fechaFin.isNull || altasBajas.fechaFin < DateTime.now` should work – Sascha Kolberg Jul 23 '15 at 14:22
  • 1
    the problem was the mapper .. now switch to this "https://github.com/tototoshi/slick-joda-mapper" and it works! Thank you very much! – Juan Pablo Vittori Jul 23 '15 at 14:40