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
andbelongs_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?