修訂 | 48 (tree) |
---|---|
時間 | 2008-02-17 15:13:36 |
作者 | junkikuchi |
updated.
@@ -16,6 +16,9 @@ | ||
16 | 16 | def accessor(row_class) |
17 | 17 | row_class.module_eval <<-END |
18 | 18 | def #{@name} |
19 | + if @row['#{@name}'].kind_of?(Tenarai::DB::Reference::Single) | |
20 | + @row['#{@name}'] = @row['#{@name}'].fetch | |
21 | + end | |
19 | 22 | @row['#{@name}'] |
20 | 23 | end |
21 | 24 | def #{@name}=(val) |
@@ -95,9 +98,10 @@ | ||
95 | 98 | class Multiple |
96 | 99 | include Enumerable |
97 | 100 | |
98 | - def initialize(link, row) | |
101 | + def initialize(link, row, val) | |
99 | 102 | @link = link |
100 | 103 | @row = row |
104 | + @val = val | |
101 | 105 | end |
102 | 106 | |
103 | 107 | def <<(row) |
@@ -105,7 +109,13 @@ | ||
105 | 109 | end |
106 | 110 | |
107 | 111 | def each(&block) |
108 | - @link.each(@row, &block) | |
112 | + @link.each(@row) do |val| | |
113 | + if val.kind_of?(Tenarai::DB::Reference::Single) | |
114 | + block.call(val.fetch) | |
115 | + else | |
116 | + block.call(val) | |
117 | + end | |
118 | + end | |
109 | 119 | end |
110 | 120 | |
111 | 121 | def size |
@@ -121,10 +131,24 @@ | ||
121 | 131 | end |
122 | 132 | end |
123 | 133 | |
134 | + class Single | |
135 | + attr_reader :primary_key | |
136 | + | |
137 | + def initialize(link, row, val) | |
138 | + @link = link | |
139 | + @row = row | |
140 | + @primary_key = val | |
141 | + end | |
142 | + | |
143 | + def fetch | |
144 | + @link.dst_table.fetch(@primary_key) | |
145 | + end | |
146 | + end | |
147 | + | |
124 | 148 | def initialize(name, param={}) |
125 | 149 | super |
126 | 150 | @param[:multiple] ||= false |
127 | - @param[:class] ||= @param[:multiple] ? Multiple : nil | |
151 | + @param[:class] ||= @param[:multiple] ? Multiple : Single | |
128 | 152 | end |
129 | 153 | |
130 | 154 | def execute(command) |
@@ -38,12 +38,12 @@ | ||
38 | 38 | end |
39 | 39 | end |
40 | 40 | |
41 | - def create_multiple(row, ref) | |
42 | - ref.param[:class].new(self, row) | |
41 | + def create_multiple(ref, row, val) | |
42 | + ref.param[:class].new(self, row, val) | |
43 | 43 | end |
44 | 44 | |
45 | - def create_single(val) | |
46 | - val && @dst_table.fetch(val) | |
45 | + def create_single(ref, row, val) | |
46 | + ref.param[:class].new(self, row, val) | |
47 | 47 | end |
48 | 48 | |
49 | 49 | def link(src_row, dst_row) |
@@ -56,6 +56,10 @@ | ||
56 | 56 | node.save |
57 | 57 | _insert(nth, node) |
58 | 58 | end |
59 | + | |
60 | + def empty? | |
61 | + (@row.min + 1) == @row.max | |
62 | + end | |
59 | 63 | end |
60 | 64 | |
61 | 65 | SQLA = "UPDATE %s SET %s = %s %s ? WHERE ? <= %s ORDER BY %s %s" |
@@ -47,13 +47,13 @@ | ||
47 | 47 | |
48 | 48 | def multiple(ref) |
49 | 49 | @handlers[ref.name] = lambda do |row, val| |
50 | - @table.relation[ref.name].create_multiple(row, ref) | |
50 | + @table.relation[ref.name].create_multiple(ref, row, val) | |
51 | 51 | end |
52 | 52 | end |
53 | 53 | |
54 | 54 | def single(ref) |
55 | 55 | @handlers[ref.name] = lambda do |row, val| |
56 | - @table.relation[ref.name].create_single(val) | |
56 | + @table.relation[ref.name].create_single(ref, row, val) | |
57 | 57 | end |
58 | 58 | end |
59 | 59 |
@@ -71,6 +71,8 @@ | ||
71 | 71 | end |
72 | 72 | end |
73 | 73 | |
74 | + widget.view.widget.load | |
75 | + | |
74 | 76 | widget.path.each do |r| |
75 | 77 | if param.empty? |
76 | 78 | if rs.key?(r.id) |
@@ -39,7 +39,7 @@ | ||
39 | 39 | end |
40 | 40 | |
41 | 41 | def build_url(param) |
42 | - nil | |
42 | + 'a' | |
43 | 43 | end |
44 | 44 | |
45 | 45 | def render_html(xml, builder) |
@@ -56,13 +56,13 @@ | ||
56 | 56 | def to_css |
57 | 57 | Tenarai::CSS.new do |css| |
58 | 58 | widget.render_css(css, self) |
59 | - end.to_s(2) | |
59 | + end.to_s(0) | |
60 | 60 | end |
61 | 61 | |
62 | 62 | def to_html |
63 | 63 | Tenarai::XML.new do |xml| |
64 | 64 | widget.render_html(xml, self) |
65 | - end.to_s(2) | |
65 | + end.to_s(0) | |
66 | 66 | end |
67 | 67 | end |
68 | 68 | end |
@@ -31,10 +31,19 @@ | ||
31 | 31 | (['?'] * vars.size).join(', ') |
32 | 32 | ] |
33 | 33 | |
34 | - @link.dst_table.each(cond, *vars) do |widget| | |
35 | - block.call(widget) | |
34 | + if block_given? | |
35 | + @link.dst_table.each(cond, *vars) do |widget| | |
36 | + block.call(widget) | |
37 | + end | |
38 | + else | |
39 | + @link.dst_table.each(cond, *vars) do |widget| | |
40 | + end | |
36 | 41 | end |
37 | 42 | end |
43 | + | |
44 | + def load | |
45 | + each | |
46 | + end | |
38 | 47 | end |
39 | 48 | |
40 | 49 | class << self |