An example of joining tables through active record models. There is a good tutorial on the basics of Activerecord joins. For this example we will have Posts and People, we will not use a grammatical parser and will beusing plural of people as peoples. (Note: should be person and persons) Create table with something like:

require 'rubygems'
require 'sequel'
DB = Sequel.sqlite('./example.db')

DB.create_table :posts do
   primary_key :id
   foreign_key :people_id, :peoples
   varchar :title
   text :body

DB.create_table :peoples do
   primary_key :id
   varchar :first_name
   varchar :last_name
   varchar :short_name

Now the active record model should be something like: NB I have added the foreign key specifier as I could not find migrations to modify it.

require 'rubygems'
require 'active_record'

   :adapter   => "sqlite3",
   :database  => "./example.db"

class People < ActiveRecord::Base
   has_many :post, :foreign_key => :people_id


class Post < ActiveRecord::Base
   # mmm No foregin key required for this
   belongs_to :people

This allows ORM automatic joins:

@person = People.first
@posts  =

@post   = Post.first
@person_name = @post.people.first_name

#Now get 3 posts by a particular author and sort
@person = People.first
@posts =, :order => "id DESC", :limit => 3)