last update: 2009-05-01 04:55:14 GMT This book is a work in progress; feel free to contribute.
Sequel::Model has a very simple set of association methods. Sequel provides many_to_one, one_to_many and many_to_many to create database associations.
class Post < Sequel::Model
one_to_many :comments
end
The Post class above now has a set of association methods similar to ActiveRecord’s has_many. The method is actually aliased to has_many, to maintain some ActiveRecord similarity.
class Post < Sequel::Model
many_to_one :user
end
The many_to_one association can also be called by belongs_to.
class Post < Sequel::Model
many_to_many :tags
end
The many_to_many association can also be called by has_and_belongs_to_many.
Sequel::Model does not have a separate method to indicate a one_to_one relationship. A :one_to_one parameter can be passed to one_to_many to create this association.
class User < Sequel::Model
one_to_many :addresses, :one_to_one => true
end