Create Models

This guide shows you how to create CQL models that map to your database tables.

Basic Model

Create a model class:

class User
  include CQL::Model(User, Int64)
  db_context AcmeDB, :users

  property id : Int64?
  property name : String
  property email : String
  property created_at : Time?
  property updated_at : Time?

  def initialize(@name = "", @email = "")
  end
end

Model with Validations

Associations

Belongs To

Has Many

Has One

Many to Many

Callbacks

Scopes

Custom Methods

JSON Serialization

See Also

Last updated

Was this helpful?