How to fetch data from ListColumn[String] in Phantom using contains condition

252 views Asked by At

I have a Cassandra table Department with columns name_list extends ListColumn[String] and id extends StringColumn with PartitionKey.

I want to fetch id where the requested name is present in name_list.

I tried using in operator select(_.id).where(name in name_list) but it is not working.

Another query I tried select(_.id).where(_.name_list contains name) but it is also not working for me.

 def getByName(name: String) = {
    select(_.id, _.name_list).where(_.name_list contains name)   
}

Is there any way to solve this!!

1

There are 1 answers

0
Akash Sethi On BEST ANSWER

You can use the SetColumn as the type for you column then you will be able to use the contains method. Use this

name_list extends SetColumn[String]

then this will work fine

def getByName(name: String) = {
    select(_.id, _.name_list).where(_.name_list contains name)   
}

Thanks