3

I have a problem when trying to create a simple list of projects. First I defined the model with three columns which should belong to a compound key.

class Project
  include Cequel::Record

  key :client, :text, { partition: true }
  key :type, :text, { partition: true }
  key :dep, :text, { partition: true }

end

Later when I try to create the Project via

project = Project.create!({client: "test", type: "test", dep: "test"})

I get the following error:

/usr/local/rvm/gems/ruby-2.1.5/gems/cequel-1.6.1/lib/cequel/record/callbacks.rb:34:in `save': undefined method `batch' for nil:NilClass (NoMethodError)

The error message is not very descriptive. Can someone help here?

---edit----

I have found the problem. After connecting, I have to set set class member of Cequel::Record.

connection = Cequel::connect(config);
Cequel::Record.connection = connection

This is probably because I don't use rails but only normal ruby.
Now I ran into another problem. The tables are not created automatically with Project.create! but I have to create the table manually first:

  connection.schema.create_table(:projects) do 
    partition_key :client, :text
    partition_key :type, :text
    partition_key :dept, :text
  end

But this syntax is different from the documented Record definition and I only found it by sifting through the source code. But this creates two problems.

  • Code overhead
  • I don't know the syntax for has_many and belongs_to so I cannot create the table correctly if the Record includes this

Am I overlooking a method to create the table automatically from the Project class definition?

Daniel82
  • 101
  • 7
  • You really need to dig through the complete stack-trace to see where that goes awry. It could be a bug in the gem. – tadman May 19 '15 at 16:02

0 Answers0