Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

nazipov/sequel_polymorphic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sequel Polymorphic

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

Version 4.x is required.

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.

About

fix Undefined method 'constantize' for Model

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%