I'm doing things with Addresses, and the member subpremise(apartment/condo #) causes retrieves to miss. I also have concerns about subpremise being a part of my unique index constraint, given it can be null.
Failure filter:
tableQuery.filter(c=> (c.longitude === r.longitude && c.latitude === r.latitude) ||
(c.streetNumber === r.streetNumber && c.route === r.route && c.subpremise === r.subpremise && c.neighborhoodId === r.neighborhoodId))
Successful filter: (by removung subpremise)
tableQuery.filter(c=> (c.longitude === r.longitude && c.latitude === r.latitude) ||
(c.streetNumber === r.streetNumber && c.route === r.route && c.neighborhoodId === r.neighborhoodId))
I've included the definitions below s.t. if there is another contributing factor that I've missed, hopefully it will be noticed.
case class Address(id:Option[Long],streetNumber:Short,route:String,subpremise:Option[String],neighborhoodId:Fk,latitude:Option[Double],longitude:Option[Double])
class Addresses(tag: Tag) extends Table[Address](tag, "addresses") with Logging {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def streetNumber = column[Short]("street_number")
def route = column[String]("route",O.NotNull)
def subpremise = column[Option[String]]("subpremise")
def neighborhoodId = column[Long]("neighborhood",O.NotNull)
def latitude = column[Option[Double]]("latitude")
def longitude = column[Option[Double]]("longitude")
//Constraints
def idx = index("idx_streetnum_route_subpremise_neighborhood", (streetNumber,route,subpremise,neighborhoodId), unique = true)
def gps = index("gps", (latitude,longitude), unique = true)
//Foreign Key
def neighborhood = foreignKey("NEIGHBORHOOD_FK", neighborhoodId, Neighborhoods.tableQuery)(_.id)
def * = (id.?,streetNumber,route,subpremise,neighborhoodId,latitude,longitude) <> (Address.tupled,Address.unapply)
}
The answer was to use the following check.
( //Option Scenario both are defined
(c.subpremise.isDefined && r.subpremise.isDefined && c.subpremise === r.subpremise) ||
//Option Scenario both are empty
(c.subpremise.isEmpty && r.subpremise.isEmpty)
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With