Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

want to know better way of joining tables with slick

Tags:

scala

slick

I have a sample query with slick as below:

val query =
  (for {
    (company,loc) <- Company leftJoin Location  on (_.locId === _.id)
    (_,typeof) <- Company leftJoin Types on (_.typeId === _.id)
  } yield (company, loc, typeof))

Is a better way to do multiple joins?

I have tried the suggestions in multiple joins with slick but resulting in errors.

like image 519
dsr301 Avatar asked Sep 04 '13 09:09

dsr301


2 Answers

This is working fine.

for {
    ((company,geo),typeof) <- Company 
        leftJoin Location on (_.locId === _.id) 
        leftJoin Business_Levels on (_._1.typeId === _.id)
}
like image 158
dsr301 Avatar answered Nov 04 '22 07:11

dsr301


You can chain the join normally :

for {
    (company, location, type) <- Company 
        leftJoin Location  on (_.locId === _.id) 
        leftJoin Types on (_._1.typeId === _.id)
} yield (company, location, type)

And by the way, I am quite sure the word type is a scala reserved word.

EDIT : Added the _.1 on line 3 after dsr301's comment.

like image 34
i.am.michiel Avatar answered Nov 04 '22 07:11

i.am.michiel