Getting an error when trying to save a record to a table

I am having a problem while trying to create a simple list of projects. First, I defined a model with three columns that should belong to the composite 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 a project via

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

      

I am getting 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 anyone help here?

--- edit ----

I found the problem. Once connected, I need to set a member of the Cequel :: Record class.

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

      

This is probably because I am not using rails, just regular ruby.
Now I am facing another problem. The tables are not automatically created with Project.create!

, but first I have to create the table manually:

  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 missing a method to automatically create a table from a class definition Project

?

+3


source to share





All Articles