0

I am using Slick for first time, as an FRM tool with Scala and MySQL.

However while writing query with multiple joins, I realised that I can't access some intermediate objects further to filter based on it.

i.e. rep1 here, which is of type Rep[Option[Manufacturer]]]

How can I unwrap this object to Manufacturer so that I can access columns of it ?

val query = product
      .joinLeft(manufacturer).on { case (prod, man) => prod.manufacturerid == man.manufacturerid }
      .joinLeft(category).on { case ((prod, rep1), cat) => prod.categoryid == cat.categoryid }
    // .filter() after this using rep1
  • Does this answer your question? [How to filter on an optional table produced by a left join in slick](https://stackoverflow.com/questions/36864185/how-to-filter-on-an-optional-table-produced-by-a-left-join-in-slick) Another option: https://stackoverflow.com/questions/43572566/slick-3-1-left-joins-and-filters – michaJlS Nov 04 '20 at 13:20

1 Answers1

0

Hello Pratik Shah and welcome to Stackoverflow.

I find it useful to think of anything inside a Rep as running in the database (as part of SQL). With that in mind, you don't unwrap a Rep: you use it within a Slick query (and the result of running the query with kind of unwrap in a sense to a plain value).

So if you can access rep1 inside the filter, you can use Slick's operators (e.g., === not ==, note) to use the Option[Manufacturer] value as part of a query. I can't say for sure without running the code but it'll perhaps be something like:

filter { case ((prod, rep1), cat) => rep1.map(_.manufacturerid) === 42 }

... or whatever you want to do with rep1

Richard Dallaway
  • 4,250
  • 1
  • 28
  • 39