O'Reilly logo

Learning Sinatra by Manoj Sehrawat, Sudeep Agarwal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to define models

Migrations are not detected by the application. The application understands models. The models will have relationships defined. When we use Sequel, we get a lot of methods to access our data store as objects. Let's now define our models.

The User model

The user model will have the following properties:

  1. Each user can add many items
  2. Each user can have permission to many lists
  3. Each user can have many logs

The file will be model/user.rb:

     1	require 'sequel' 
     2	 
     3	class User < Sequel::Model 
     4	  set_primary_key :id 
     5	 
     6	  one_to_many :items 
     7	  one_to_many :permissions 
     8	  one_to_many :logs 
     9	end 

Let's understand each line one by one:

  • Line 3: class User < Sequel::Model tells the application to inherit the Model class of the Sequel module
  • Line 4:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required