0

Quill does not parse embedded option class if it's two-level option embedded class is None

Version: 3.4.10 Module: quill-jdbc-monix Database: postgresql

Steps to reproduce the behavior

I have the next classes:

case class Customer(id: String, personData: Option[PersonData] = None)
case class PersonData(firstName: String, address: Option[Address] = None) extends Embedded
case class Address(country: String, city: String) extends Embedded

run(quote {
      query[Customer]
        .filter(_.id == lift(id))
    }).map(_.headOption)

If all fields are filled in the database then the query works fine. If address fields (country, city) are null in the database but person data field firstName is filled then the personData field in Customer is None. But I expected that the personData should be Some and only address field in it should be None

Anar Amrastanov
  • 385
  • 1
  • 3
  • 13
  • It could be better if you specify `country` and `city` fields as `Option` if they are nullable in db – Duelist Nov 28 '19 at 13:27
  • these fields are mandatory. If address exist then these fields should be filled – Anar Amrastanov Nov 28 '19 at 21:19
  • If they are mandatory, why they are nullable in database? You mentioned that "If address fields (`country`, `city`) are `null` in the database ..." – Duelist Nov 29 '19 at 08:13
  • `Address` is an embedded class. These fields are mandatory in `Address`, but address whole is not mandatory in the `PersonData`, so in `Customer` too. If these fields in a database will be nullable then there will be a situation like a `personData` will have a field `address = Some(Address(None, None))` – Anar Amrastanov Nov 29 '19 at 11:51
  • So in `address` table these fields aren't nullabe. but in `customer` table foreign key that refers to `personData` table is nullable. Am I right? – Duelist Nov 29 '19 at 11:58
  • No. In the Customer table these fields are plain. Only one table `customer` in the database with all fields. But in code `PersonData` and `Address` are `Embedded` so quill should be able to distribute these fields into to main class `Customer` and embedded classes `PersonData` and `Address` – Anar Amrastanov Nov 29 '19 at 12:12
  • Please describe the tables in the question – Duelist Nov 29 '19 at 12:33

0 Answers0