/usr/lib/ruby/1.8/ramaze/contrib/sequel/create_join.rb is in libramaze-ruby1.8 2010.06.18-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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
|