Sha256: b82c93c32ba0b28fdf72ac2166ff63aa0c2e0c3733d6a249fb5fbdd4720d85b2

Contents?: true

Size: 692 Bytes

Versions: 17

Compression:

Stored size: 692 Bytes

Contents

require 'sequel'

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

17 entries across 17 versions & 4 rubygems

Version Path
Pistos-ramaze-2008.09 lib/ramaze/contrib/sequel/create_join.rb
Pistos-ramaze-2008.12 lib/ramaze/contrib/sequel/create_join.rb
Pistos-ramaze-2009.01 lib/ramaze/contrib/sequel/create_join.rb
Pistos-ramaze-2009.02 lib/ramaze/contrib/sequel/create_join.rb
Pistos-ramaze-2009.04.08 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2008.09 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2008.10 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2008.12 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.01 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.04.01 lib/ramaze/contrib/sequel/create_join.rb
manveru-ramaze-2009.04.08 lib/ramaze/contrib/sequel/create_join.rb
ptomato-ramaze-2009.02.1 lib/ramaze/contrib/sequel/create_join.rb
ptomato-ramaze-2009.02 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2008.11 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2009.01 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2009.02 lib/ramaze/contrib/sequel/create_join.rb
ramaze-2009.03 lib/ramaze/contrib/sequel/create_join.rb