# ANN: Sequel 1.3 Released

**URL:** <https://www.ruby-forum.com/t/ann-sequel-1-3-released/131359>\
**Category:** Ruby\
**Created:** [March 8, 2008, 8:16pm UTC](https://www.ruby-forum.com/t/ann-sequel-1-3-released/131359 "2008-03-08T20:16:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ciconia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/71c47a/32.png) [@ciconia](https://www.ruby-forum.com/u/ciconia)\
**Post date:** [March 8, 2008, 8:16pm UTC](https://www.ruby-forum.com/t/ann-sequel-1-3-released/131359/1 "2008-03-08T20:16:35Z")

</div>

Sequel version 1.3 has just been released. Sequel is a lightweight  
database access toolkit for Ruby. Sequel provides thread safety,  
connection pooling and a simple and expressive API for constructing  
database queries and table schemas. Sequel also includes an ORM layer  
following the ActiveRecord pattern.

The latest release of Sequel includes improved model associations and  
many bug fixes. Following is a summary of the changes:

=== Better model associations

The latest release of sequel\_model includes a new associations  
functionality written by Jeremy E. which replaces the old relations  
code in previous versions. Please note that this version is not  
completely backward-compatible and you should therefore upgrade with  
caution.

The new implementation supports three kinds of relations: one\_to\_many,  
many\_to\_one and many\_to\_many, which correspond to has\_many, belongs\_to  
and has\_and\_belongs\_to\_many relations in ActiveRecord. In fact, the  
new implementation includes aliases for ActiveRecord assocation macros  
and is basically compatible with ActiveRecord conventions. It also  
supports DRY implicit class name references. Here’s a simple example:

class Author \< Sequel::Model  
has\_many :books # equivalent to one\_to\_many  
end

class Book \< Sequel::Model  
belongs\_to :author # equivalent to many\_to\_one  
has\_and\_belongs\_to\_many :categories # equivalent to many\_to\_many  
end

class Category \< Sequel::Model  
has\_and\_belongs\_to\_many :books  
end

These macros will create the following methods:

- Author#books, Author#add\_book, Author#remove\_book
- Book#author, Book#categories, Book#add\_category,  
Book#remove\_category
- Category#books, Category#add\_book, Category#remove\_book

Unlike ActiveRecord, one\_to\_many and many\_to\_many association methods  
return a dataset:

a = Author[1234]  
a.books.sql #=\> ‘SELECT \* FROM books WHERE (author\_id = 1234)’

You can also tell Sequel to cache the association result set and  
return it as an array:

class Author \< Sequel::Model  
has\_many :books, :cache =\> true  
end

Author[1234].books.class #=\> Array

You can of course bypass the defaults and specify class names and key  
names:

class Node \< Sequel::Model  
belongs\_to :parent, :class =\> Node  
belongs\_to :session, :key =\> :producer\_id  
end

Another useful option is :order, which sets the order for the  
association dataset:

class Author \< Sequel::Model  
has\_many :books, :order =\> :title  
end

Author[1234].books.sql #=\> ‘SELECT \* FROM books WHERE (author\_id =  
1234) ORDER BY title’

More information about associations can be found in the Sequel  
documentation.

=== Other changes

- Added configuration file for running specs (#186).

- Changed Database#drop\_index to accept fixed arity (#173).

- Changed column definition sql to put UNSIGNED constraint before  
unique in order to satisfy MySQL (#171).

- Enhanced MySQL adapter to support load data local infile\_, added  
compress option for mysql connection by default (#172).

- Fixed bug when inserting hashes in array tuples mode.

- Changed SQLite adapter to catch RuntimeError raised when executing a  
statement and raise Error::InvalidStatement with the offending SQL and  
error message (#188).

- Fixed Dataset#reverse to not raise for unordered dataset (#189).

- Added Dataset#unordered method and changed #order to remove order if  
nil is specified (#190).

- Fixed reversing order of ASC expression (#164).

- Added support for :null =\> true option when defining table columns  
(#192).

- Fixed Symbol#method\_missing to accept variable arity (#185).

=== More info on Sequel

Sequel project page:  
[http://code.google.com/p/ruby-sequel](http://code.google.com/p/ruby-sequel)

Sequel documentation:  
[http://sequel.rubyforge.org](http://sequel.rubyforge.org)

Join the Sequel-talk group:  
[http://groups.google.com/group/sequel-talk](http://groups.google.com/group/sequel-talk)

Join Sequel discussion on IRC at #sequel.

Install the gem:  
sudo gem install sequel

Or check out the source and install manually:  
svn co [http://ruby-sequel.googlecode.com/svn/trunk](http://ruby-sequel.googlecode.com/svn/trunk) sequel  
cd sequel  
rake install
