Sha256: 664b18d0e00825ab1cdc0431469dff2c2cab0ff9d00cea5c638c701838c69b45

Contents?: true

Size: 730 Bytes

Versions: 26

Compression:

Stored size: 730 Bytes

Contents

require 'sequel'
require 'sequel/extensions/inflector'

module Sequel
  class Model
    # Force join table generation
    #
    # Usage:
    #   User.create_join(Article, 'articles_users')
    #   # or let the method figure out the correct join table using sequel
    #   # conventions.
    #   User.create_join(Article)
    def self.create_join(to, name = nil)
      from = self
      name ||= [table_name.to_s, to.table_name.to_s].sort.join('_')
      from_key = "#{from.table_name.to_s.singularize}_id"
      to_key = "#{to.table_name.to_s.singularize}_id"

      db.create_table! name do
        primary_key :id
        foreign_key from_key, :class => from
        foreign_key to_key, :class => to
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 4 rubygems

Version Path
Pistos-ramaze-2009.06.12 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.04.18 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.04.22 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.04 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.05.08 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.05 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.06.04 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.06.12 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.06 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.07 lib/ramaze/contrib/sequel/create_join.rb
rjspotter-ramaze-2009.06.29 lib/ramaze/contrib/sequel/create_join.rb
rjspotter-ramaze-2009.06.31 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2011.01.30 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2011.01 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2010.06.18 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2010.04.04 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2010.04 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2010.03 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2010.01 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2009.10 lib/ramaze/contrib/sequel/create_join.rb