This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge branch 'english'

* english:
  Adding myself as a contributor.
  An example of Sequel::Model.subset
  Adding language specs to the code snippets in sequel plugins.
  Sequel test dbs need to be migrated manually.
  Whoops.  Lost the links in the merge.
  Adding a short intro to Sequel paragraph in the first section of the chapter.
  Renaming the firstsection.
  A little supplementary information for sequel associations.
  • Loading branch information...
mattetti committed Jan 26, 2009
2 parents 1a1d3e7 + 10c0859 commit c79b2e82e017f00bb4c1fe4fa10fec79a419fcf1
@@ -8,6 +8,7 @@ Thank you all!
* [Matt Aimonetti ](http://merbist.com)
* [Fabio Akita ](http://akitaonrails.com)
* [Dale Campbell ](http://corrupt.save-state.net/)
+* [Jacob Dunphy ](http://github.com/jdunphy/)
* [Matthew Ford ](http://github.com/deimos1986)
* [Mathieu Fosse ](http://blog.kawooa.org)
* [Yehuda Katz ](http://yehudakatz.com)
@@ -1,4 +1,9 @@
-#Installation and setup
+#Getting started
+
+[Sequel][] is a full-fledged, mature ORM database toolkit that has support for object models.
+It's supported as a drop-in ORM option with Merb using the merb\_sequel plugin.
+Sequel also features an easy-to-use plugin syntax to extend default functionality.
+The [Sequel documentation][] is very thorough, and has some good usage examples.
##Generating a project with Sequel
@@ -22,5 +27,6 @@ This will generate an app that uses Sequel, rspec, and the rest of what can be e
By default, `merb-gen sequel-app` will generate a database.yml file that uses sqlite3.
For more info, check out the [repository][].
-
-[repository]: http://github.com/jackdempsey/merb-sequel-stack/tree
+[Sequel]: http://sequel.rubyforge.org
+[Sequel documentation]: http://sequel.rubyforge.org/documentation.html
+[repository]: http://github.com/jackdempsey/merb-sequel-stack/tree
@@ -50,4 +50,10 @@ After editing the migration, it can be run with a rake task.
$ rake sequel:db:migrate
-A VERSION flag can be specified to roll back to particular migration versions.
+A VERSION flag can be specified to roll back to particular migration versions.
+
+A database for the test environment will not built automatically.
+To run tests, the test database will need to be migrated as well.
+A MERB\_ENV variable can be passed to the rake task.
+
+ $ rake sequel:db:migrate MERB_ENV=test
@@ -30,6 +30,18 @@ To simplify the following examples, the SQL statements produced by Sequel::Model
>> Post.order(:created_at.desc).paginate(2, 10).all
~ SELECT * FROM `posts` ORDER BY `created_at` DESC LIMIT 10 OFFSET 10
+Rewriting filters like these on a regular basis can be a pain.
+Sequel supports subset methods that create easy-to-reuse filters.
+
+ class Post < Sequel::Model
+ subset(:recent, :created_at > Date.today - 3)
+ end
+
+ # You can then call
+ Post.recent.filter(:user_id => 1).all
+{:lang=ruby html_use_syntax=true}
+
+
##The Other Three Letters in CRUD
###Create
@@ -13,7 +13,8 @@ Sequel provides `many_to_one`, `one_to_many` and `many_to_many` to create databa
-The Post class above now has a set of association methods similar to ActiveRecord's has\_many.
+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.
##Many to One
@@ -22,15 +23,22 @@ The Post class above now has a set of association methods similar to ActiveRecor
end
{:lang=ruby html_use_syntax=true}
+The `many_to_one` association can also be called by `belongs_to`.
+
##Many to Many
class Post < Sequel::Model
many_to_many :tags
end
{:lang=ruby html_use_syntax=true}
+The `many_to_many` association can also be called by `has_and_belongs_to_many`.
+
## One to One
+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
@@ -16,6 +16,7 @@ As the name would indicate, sequel\_timestamped will update standard timestamp c
class Note < Sequel::Model
is :timestamped
end
+{:lang=ruby html_use_syntax=true}
If the model has `created_at` and `updated_at` timestamp columns, they will be updated as expected.
@@ -35,6 +36,7 @@ Not-naughty is a gem that provides an easily extensible validation framework.
length_of :login, :minimum => 5
end
end
+{:lang=ruby html_use_syntax=true}
Here's the [sequel\_notnaughty source][], and the [not-naughty source][].
@@ -53,6 +55,7 @@ The plugin adds functionality to Sequel's associations to handle these situation
is :polymorphic
many_to_one :attachable, :polymorphic => true
end
+{:lang=ruby html_use_syntax=true}
This will create a transparent polymorphic relationship between the Note and its Assets.
@@ -1,6 +1,5 @@
-# interacting-with-the-database-sequel
- <ul class='toc'><li><a href='/en/interacting-with-the-database-sequel/up'>Installation and setup</a><ul style='list-style: none;'><li><a href='/en/interacting-with-the-database-sequel/up#generating_a_project_with_sequel'>Generating a project with Sequel</a></li></ul></li></ul>
+<ul class='toc'><li><a href='/en/interacting-with-the-database-sequel/up'>Installation and setup</a><ul style='list-style: none;'><li><a href='/en/interacting-with-the-database-sequel/up#generating_a_project_with_sequel'>Generating a project with Sequel</a></li></ul></li></ul>
<ul class='toc'><li><a href='/en/interacting-with-the-database-sequel/migrations'>Database Migrations</a></li></ul>
@@ -44,7 +44,7 @@ frequently, **please consider helping improve the content of this book**.
1. [Installation and setup](/interacting-with-the-database-active_record/setting-up)
1. [Database Queries](/interacting-with-the-database-active_record/queries)
1. [Interacting with the database (Sequel)](/interacting-with-the-database-sequel)
- 1. [Installation and setup](/interacting-with-the-database-sequel/setting-up)
+ 1. [Getting Started](/interacting-with-the-database-sequel/getting-started)
1. [Database Migrations](/interacting-with-the-database-sequel/migrations)
1. [Data Retrieval and Manipulation](/interacting-with-the-database-sequel/data-retrieval-and-manipulation)
1. [Model Associations](/interacting-with-the-database-sequel/model-associations)

0 comments on commit c79b2e8

Please sign in to comment.