Showing 2 changed files with 94 additions and 93 deletions
+94
t/common.t
... ...
@@ -3015,4 +3015,98 @@ $dbi->select(
3015 3015
 };
3016 3016
 like($@, qr/array/);
3017 3017
 
3018
+test 'dbi method from model';
3019
+$dbi = MyDBI9->connect;
3020
+eval { $dbi->execute('drop table table1') };
3021
+$dbi->execute($create_table1);
3022
+$dbi->setup_model;
3023
+$model = $dbi->model('table1');
3024
+eval{$model->execute('select * from table1')};
3025
+ok(!$@);
3026
+
3027
+test 'column table option';
3028
+$dbi = MyDBI9->connect;
3029
+eval { $dbi->execute('drop table table1') };
3030
+$dbi->execute($create_table1);
3031
+eval { $dbi->execute('drop table table2') };
3032
+$dbi->execute($create_table2);
3033
+$dbi->setup_model;
3034
+$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
3035
+$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
3036
+$model = $dbi->model('table1');
3037
+$result = $model->select(
3038
+    column => [
3039
+        $model->column('table2', {alias => 'table2_alias'})
3040
+    ],
3041
+    where => {'table2_alias.key3' => 4}
3042
+);
3043
+is_deeply($result->one, 
3044
+          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
3045
+
3046
+$dbi->separator('__');
3047
+$result = $model->select(
3048
+    column => [
3049
+        $model->column('table2', {alias => 'table2_alias'})
3050
+    ],
3051
+    where => {'table2_alias.key3' => 4}
3052
+);
3053
+is_deeply($result->one, 
3054
+          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
3055
+
3056
+$dbi->separator('-');
3057
+$result = $model->select(
3058
+    column => [
3059
+        $model->column('table2', {alias => 'table2_alias'})
3060
+    ],
3061
+    where => {'table2_alias.key3' => 4}
3062
+);
3063
+is_deeply($result->one, 
3064
+          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
3065
+
3066
+test 'create_model';
3067
+$dbi = DBIx::Custom->connect;
3068
+eval { $dbi->execute('drop table table1') };
3069
+eval { $dbi->execute('drop table table2') };
3070
+$dbi->execute($create_table1);
3071
+$dbi->execute($create_table2);
3072
+
3073
+$dbi->create_model(
3074
+    table => 'table1',
3075
+    join => [
3076
+       'left outer join table2 on table1.key1 = table2.key1'
3077
+    ],
3078
+    primary_key => ['key1']
3079
+);
3080
+$model2 = $dbi->create_model(
3081
+    table => 'table2'
3082
+);
3083
+$dbi->create_model(
3084
+    table => 'table3',
3085
+    filter => [
3086
+        key1 => {in => sub { uc $_[0] }}
3087
+    ]
3088
+);
3089
+$dbi->setup_model;
3090
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
3091
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3092
+$model = $dbi->model('table1');
3093
+$result = $model->select(
3094
+    column => [$model->mycolumn, $model->column('table2')],
3095
+    where => {'table1.key1' => 1}
3096
+);
3097
+is_deeply($result->one,
3098
+          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
3099
+is_deeply($model2->select->one, {key1 => 1, key3 => 3});
3100
+
3101
+test 'model method';
3102
+$dbi = DBIx::Custom->connect;
3103
+eval { $dbi->execute('drop table table2') };
3104
+$dbi->execute($create_table2);
3105
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
3106
+$model = $dbi->create_model(
3107
+    table => 'table2'
3108
+);
3109
+$model->method(foo => sub { shift->select(@_) });
3110
+is_deeply($model->foo->one, {key1 => 1, key3 => 3});
3111
+
3018 3112
 1;
-93
t/sqlite.t
... ...
@@ -211,99 +211,6 @@ $dbi->execute("insert into table1 (key1) values (:table2.key1)", {'table2.key1'
211 211
 $result = $dbi->select(table => 'table1');
212 212
 is($result->one->{key1}, 'A');
213 213
 
214
-test 'dbi method from model';
215
-$dbi = MyDBI9->connect;
216
-eval { $dbi->execute('drop table table1') };
217
-$dbi->execute($create_table1);
218
-$dbi->setup_model;
219
-$model = $dbi->model('table1');
220
-eval{$model->execute('select * from table1')};
221
-ok(!$@);
222
-
223
-test 'column table option';
224
-$dbi = MyDBI9->connect;
225
-eval { $dbi->execute('drop table table1') };
226
-$dbi->execute($create_table1);
227
-eval { $dbi->execute('drop table table2') };
228
-$dbi->execute($create_table2);
229
-$dbi->setup_model;
230
-$dbi->execute('insert into table1 (key1, key2) values (1, 2);');
231
-$dbi->execute('insert into table2 (key1, key3) values (1, 4);');
232
-$model = $dbi->model('table1');
233
-$result = $model->select(
234
-    column => [
235
-        $model->column('table2', {alias => 'table2_alias'})
236
-    ],
237
-    where => {'table2_alias.key3' => 4}
238
-);
239
-is_deeply($result->one, 
240
-          {'table2_alias.key1' => 1, 'table2_alias.key3' => 4});
241
-
242
-$dbi->separator('__');
243
-$result = $model->select(
244
-    column => [
245
-        $model->column('table2', {alias => 'table2_alias'})
246
-    ],
247
-    where => {'table2_alias.key3' => 4}
248
-);
249
-is_deeply($result->one, 
250
-          {'table2_alias__key1' => 1, 'table2_alias__key3' => 4});
251
-
252
-$dbi->separator('-');
253
-$result = $model->select(
254
-    column => [
255
-        $model->column('table2', {alias => 'table2_alias'})
256
-    ],
257
-    where => {'table2_alias.key3' => 4}
258
-);
259
-is_deeply($result->one, 
260
-          {'table2_alias-key1' => 1, 'table2_alias-key3' => 4});
261
-
262
-test 'create_model';
263
-$dbi = DBIx::Custom->connect;
264
-eval { $dbi->execute('drop table table1') };
265
-eval { $dbi->execute('drop table table2') };
266
-$dbi->execute($create_table1);
267
-$dbi->execute($create_table2);
268
-
269
-$dbi->create_model(
270
-    table => 'table1',
271
-    join => [
272
-       'left outer join table2 on table1.key1 = table2.key1'
273
-    ],
274
-    primary_key => ['key1']
275
-);
276
-$model2 = $dbi->create_model(
277
-    table => 'table2'
278
-);
279
-$dbi->create_model(
280
-    table => 'table3',
281
-    filter => [
282
-        key1 => {in => sub { uc $_[0] }}
283
-    ]
284
-);
285
-$dbi->setup_model;
286
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
287
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
288
-$model = $dbi->model('table1');
289
-$result = $model->select(
290
-    column => [$model->mycolumn, $model->column('table2')],
291
-    where => {'table1.key1' => 1}
292
-);
293
-is_deeply($result->one,
294
-          {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
295
-is_deeply($model2->select->one, {key1 => 1, key3 => 3});
296
-
297
-test 'model method';
298
-$dbi = DBIx::Custom->connect;
299
-eval { $dbi->execute('drop table table2') };
300
-$dbi->execute($create_table2);
301
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
302
-$model = $dbi->create_model(
303
-    table => 'table2'
304
-);
305
-$model->method(foo => sub { shift->select(@_) });
306
-is_deeply($model->foo->one, {key1 => 1, key3 => 3});
307 214
 
308 215
 test 'join';
309 216
 $dbi = DBIx::Custom->connect;