Search code examples
ruby-on-railsruby-on-rails-4cassandracequel

ArgumentError when calling directly a query with cequel


I've just updated cequel from 1.10.0 to 3.2.1 and I'm having the following model:

module Messaging
  class ThreadsForUser
    include Cequel::Record
    include Sunspot::Cequel

    self.table_name = :messaging_threads_for_users

    key :user_id, :bigint
    key :thread_id, :timeuuid, order: :desc

and I have the following query (this was working correctly with 1.1.0):

  connection.execute(
    "DELETE FROM #{table_name} WHERE thread_id = ? AND user_id in (?)",
    thread_id, user_ids
  )

but with 3.2.1 I'm receiving:

ArgumentError: argument for "user_id" must be bigint, [3] given

where user_ids is an array with a 3 on it. Not sure how can I fix this, any idea?


Solution

  • You need to use syntax as here:

    DELETE FROM #{table_name} WHERE thread_id = ? AND user_id in ?
    

    In this case the full list will be substituted by driver into in, while in your variant, you're passing the IN consisting of one element - it's valid syntax, you simply need to pass integer value instead of list of integers.