No description, website, or topics provided.
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 20 commits ahead, 54 commits behind jackdempsey:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
Gemfile
LICENSE
README.md
Rakefile
TODO
sequel_polymorphic.gemspec

README.md

Sequel Polymorphic

A simple plugin for Sequel::Model's that lets you easily create polymorphic associations.

Usage

Models

Sequel::Model.plugin(:polymorphic)

class Asset < Sequel::Model
  belongs_to :attachable, :polymorphic => true
end

class Note < Sequel::Model
  has_many :assets, :as => :attachable
end

class Post < Sequel::Model
  has_many :assets, :as => :attachable
end

Schema

Include the polymorphic columns in your DB schema:

Sequel.migration do
  change do
    create_table :assets do
      # ...
      Integer :attachable_id
      String :attachable_type
      # ...
      index [:attachable_id, :attachable_type]
    end
  end
end

Similar to ActiveRecord Style

class Asset < ActiveRecord::Base
  belongs_to :attachable, :polymorphic => true
end

class Post < ActiveRecord::Base
  has_many :assets, :as => :attachable
end

class Note < ActiveRecord::Base
  has_many :assets, :as => :attachable
end

Sequel (without the polymorphic plugin)

Check the Advanced Associations section of the Sequel docs (search "Polymorphic Associations")