grails - Search records having comma seperated values that contains any element from the given list -


i have domain class schedule property 'days' holding comma separated values '2,5,6,8,9'.

class schedule {    string days    ... }  schedule schedule1 = new schedule(days :'2,5,6,8,9') schedule1.save()  schedule schedule2 = new schedule(days :'1,5,9,13') schedule2.save() 

i need list of schedules having day given list [2,8,11].

output: [schedule1]

how write criteria query or hql same. can prefix & suffix days comma ',2,5,6,8,9,' if helps.

thanks,

hope have reason such denormalization - otherwise better save list child table.

otherwise, querying complicated. like:

  def days = [2,8,11]   // note check empty days   schedule.withcriteria {     days.each { day ->       or {         like('username', "$day,%") // starts "$day"         like('username', "%,$day,%")         like('username', "%,$day") // ends "$day"       }     }   } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -