title: Slick Generic Query return type
body: <p>I am making a function that filters a query in slick as following:</p>
  
  <pre><code>class Foos(tag: Tag) extends RichTable[Foo](tag, "t_foo") {
      // foo slick mapping
  }
  </code></pre>
  
  <p><strong>working function</strong></p>
  
  <pre><code>object Foos extends PostgresGeneric[Foos, Foo] {
      private def filterQuery(query :Query[Foos,Foos#TableElementType,Seq], searchFilter: FooFilter) = {
          var filteredQuery = query
  
          if(searchFilter.searchEntity.isDefined) {
            val searchEntity = searchFilter.searchEntity.get
  
            if(searchEntity.cancelled.isDefined) {
              filteredQuery = filteredQuery.filter(p =&gt; p.cancelled === searchEntity.cancelled.get)
            }
  
            if(searchEntity.nome.isDefined) {
              filteredQuery = filteredQuery.filter(p =&gt; p.nome.toLowerCase like "%"+searchEntity.nome.get.toLowerCase()+"%")
            }
  
            if(searchEntity.localidade.isDefined) {
              filteredQuery = filteredQuery.filter(_.localidade === searchEntity.localidade)
            }
          }
  
          filteredQuery
      }
  }
  </code></pre>
  
  <p><strong>not working function</strong></p>
  
  <pre><code>object Foos extends PostgresGeneric[Foos, Foo] {
      private def filterQuery(query :Query[Foos,Foos#TableElementType,Seq], searchFilter: FooFilter) = {
          var filteredQuery = query
  
          if(searchFilter.searchEntity.isDefined) {
            val searchEntity = searchFilter.searchEntity.get
  
            if(searchEntity.cancelled.isDefined) {
              filteredQuery = filteredQuery.filter(p =&gt; p.cancelled === searchEntity.cancelled.get)
            }
  
            if(searchEntity.nome.isDefined) {
              filteredQuery = filteredQuery.filter(p =&gt; p.nome.toLowerCase like "%"+searchEntity.nome.get.toLowerCase()+"%")
            }
  
            if(searchEntity.localidade.isDefined) {
              filteredQuery = filteredQuery.filter(_.localidade === searchEntity.localidade)
              filteredQuery = filteredQuery.join(tableReferenceFoo2).on(_.foo2 === _.id)
            }
          }
  
          filteredQuery
      }
  }
  </code></pre>
  
  <p><strong>error message</strong></p>
  
  <pre><code>Error:(165, 76) type mismatch;
   found   : scala.slick.lifted.Query[(model.db.entity.Foos, model.db.entity.Foos2),(model.db.entity.Foo, model.db.entity.Foos2#TableElementType),Seq]
      (which expands to)  scala.slick.lifted.Query[(model.db.entity.Foos, model.db.entity.Foos2),(model.db.entity.Foo, model.db.entity.Foo2),Seq]
   required: slick.driver.PostgresDriver.simple.Query[model.db.entity.Foos,model.db.entity.Foo,Seq]
      (which expands to)  scala.slick.lifted.Query[model.db.entity.Foos,model.db.entity.Foo,Seq]
          filteredQuery = filteredQuery.join(tableReferenceFoo2).on(_.Foo2 === _.id)
  </code></pre>
  
  <p>The first code works because the resulting query has always the same type after the filtering. It fails after the join, because the type changes.</p>
  
  <p><strong>Porblem:</strong> </p>
  
  <p>this function works OK until I need to perform a join with another table.</p>
  
  <p>So, how could I type this Query instance in a way it would accept a type that would mount any kind of query? Is it possible?</p>