gist: 14532 Download_button fork
public
Public Clone URL: git://gist.github.com/14532.git
Text
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'rubygems'
require 'sequel'
 
DB = Sequel.connect('jdbc:mysql://localhost/sequel_test?user=root&password=')
 
DB.create_table! :policies do # Create a new table
  primary_key :id, :serial
  date :term_start_date
  varchar :policy_ref, :size => 30
end
 
DB.create_table! :covers do
  primary_key :id, :serial
  foreign_key :policy_id, :policies
  varchar :cover_code, :size => 30
  boolean :is_primary
end
 
DB.create_table! :mod_factors do
  integer :policy_id
  varchar :cover_code, :size => 30
  varchar :prem_mod_type
  float :prem_mod_value
# foreign_key [:policy_id, :cover_code], :covers
end
 
class Policy < Sequel::Model
  set_primary_key :id
  has_many :covers
  set_allowed_columns :term_start_date, :policy_ref, :cover_attributes
 
  def after_initialize
    puts self.id
    1.upto(3) do |i|
      add_cover(Cover.new({:cover_code => i}))
    end
  end
 
  def cover_attributes=(attribs)
    puts "cover_attributes="
  end
end
 
class Cover < Sequel::Model
  has_many :mod_factors
  belongs_to :policy
end
 
class ModFactor < Sequel::Model
  belongs_to :cover
end
 
p = Policy.new.set({
      :term_start_date => Date.today,
      :cover_attributes => [{:cover_code => "1020"}]})
 
p.save
 
 

Owner

tothda

Revisions