Class: Sequel::Model

Inherits:
Object show all
Defined in:
lib/ramaze/contrib/sequel/fill.rb,
lib/ramaze/contrib/sequel/create_join.rb

Class Method Summary collapse

Class Method Details

.create_join(to, name = nil) ⇒ Object

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)


12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ramaze/contrib/sequel/create_join.rb', line 12

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

.fill(request_object = Ramaze::Request.current) ⇒ Object



7
8
9
# File 'lib/ramaze/contrib/sequel/fill.rb', line 7

def fill request_object = Ramaze::Request.current
  create(request_object.params)
end