Skip to content

jackdempsey/sequel_polymorphic

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Sequel Polymorphic (unmaintained)

A plugin for Sequel that lets you easily create polymorphic associations.

Required:

  • Sequel >= 4.0.0 and Ruby >= 1.8.7,
  • or Sequel >= 5.0.0 and Ruby >= 1.9.2.

(Note: Ruby 1.8.7 option is not tested.)

Usage examples

Models

Sequel::Model.plugin(:polymorphic)

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

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

class Post < Sequel::Model
  one_to_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

More usage examples

See specs.

Important note

See here.

Feedback and contribute

https://github.com/jackdempsey/sequel_polymorphic

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages