# Defining your model

Model definition in Clear is done by inclusion of the Clear::Model module in your class. Assuming we have this table in PostgreSQL:

```sql
CREATE TABLE articles (
   id serial NOT NULL PRIMARY KEY,
   name text NOT NULL,
   description text
);
```

The definition of this model is straight forward:

{% code title="article.cr" %}

```ruby
class Article
  include Clear::Model

  column name : String
  column description : String?

  column id : Int32, primary: true, presence: false
end
```

{% endcode %}

Cut step by step, this is what happens:

First, we include all the magic of Clear in our class:

```ruby
include Clear::Model
```

Second, we define `name` column as String. Clear will map automatically the column to the model attribute.&#x20;

```ruby
column name : String
```

Third, we define `description` . We defined `description`as `NULLABLE` in our database. To reflect this choice, we add `Nilable` `?` operator to our column.

```
column description : String?
```

Finally, we define `id` as our primary key for this model. While being declared as `NOT NULL`, the column is defined with a default value in PostgreSQL. Therefore, we tell Clear to not check value presence on save/validate by adding `presence: false` to the column definition.

```ruby
column id : Int32, primary: true, presence: false
```

You may now use your model :

```ruby
a = Article.new({name: "A superb article!" })
a.description = "This is a master piece!"
a.save!

puts "Article has been properly saved as id=#{a.id}"
```

By default, Clear will inflect the model name and use plural lower case version of the model name as table name (here `articles`).

You may want to override this behavior, by redefining `self.table` :

```ruby
class Model::Customer
  include Clear::Model

  self.table = "clients" #< Different from infered "model_customers" table.
  # ...
end
```

Next article is covering deeply the column definition and its subtleties.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clear.gitbook.io/project/model/column-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
