... | ... |
@@ -1,7 +1,9 @@ |
1 | 1 |
0.1648 |
2 |
- add DBIx::Custom::Model columns attirbute |
|
3 |
- add DBIx::Custom::Model foreign_key() attribute |
|
4 |
- add models() attribute |
|
2 |
+ add experimental each_table() method |
|
3 |
+ add experimental setup_model() |
|
4 |
+ add experimental DBIx::Custom::Model columns attirbute |
|
5 |
+ add experimental DBIx::Custom::Model foreign_key() attribute |
|
6 |
+ add experimental models() attribute |
|
5 | 7 |
0.1647 |
6 | 8 |
add default_dbi_option() |
7 | 9 |
0.1646 |
... | ... |
@@ -666,6 +666,20 @@ sub include_model { |
666 | 666 |
return $self; |
667 | 667 |
} |
668 | 668 |
|
669 |
+sub setup_model { |
|
670 |
+ my $self = shift; |
|
671 |
+ |
|
672 |
+ $self->each_column( |
|
673 |
+ sub { |
|
674 |
+ my ($self, $table, $column, $column_info) = @_; |
|
675 |
+ |
|
676 |
+ if (my $model = $self->models->{$table}) { |
|
677 |
+ push @{$model->columns}, $column; |
|
678 |
+ } |
|
679 |
+ } |
|
680 |
+ ); |
|
681 |
+} |
|
682 |
+ |
|
669 | 683 |
our %VALID_UPDATE_ARGS |
670 | 684 |
= map { $_ => 1 } qw/table param |
671 | 685 |
where append filter allow_update_all query/; |
... | ... |
@@ -1222,9 +1236,9 @@ Return value of C<insert()> is the count of affected rows. |
1222 | 1236 |
|
1223 | 1237 |
$dbi->each_column( |
1224 | 1238 |
sub { |
1225 |
- my ($self, $table, $column, $info) = @_; |
|
1239 |
+ my ($self, $table, $column, $column_info) = @_; |
|
1226 | 1240 |
|
1227 |
- my $type = $info->{TYPE_NAME}; |
|
1241 |
+ my $type = $column_info->{TYPE_NAME}; |
|
1228 | 1242 |
|
1229 | 1243 |
if ($type eq 'DATE') { |
1230 | 1244 |
# ... |
... | ... |
@@ -1235,7 +1249,7 @@ Get column informations from database. |
1235 | 1249 |
Argument is callback. |
1236 | 1250 |
You can do anything in callback. |
1237 | 1251 |
Callback receive four arguments, dbi object, table name, |
1238 |
-column name and columninformation. |
|
1252 |
+column name and column information. |
|
1239 | 1253 |
|
1240 | 1254 |
=head2 C<(experimental) include_model> |
1241 | 1255 |
|
... | ... |
@@ -1420,6 +1434,13 @@ Return value of C<update()> is the count of affected rows. |
1420 | 1434 |
|
1421 | 1435 |
Set and get a L<DBIx::Custom::Model> object, |
1422 | 1436 |
|
1437 |
+=head2 C<(experimental) setup_model> |
|
1438 |
+ |
|
1439 |
+ $dbi->setup_model; |
|
1440 |
+ |
|
1441 |
+Setup all model objects. |
|
1442 |
+C<columns> and C<primary_key> is automatically set. |
|
1443 |
+ |
|
1423 | 1444 |
=head2 C<update_all> |
1424 | 1445 |
|
1425 | 1446 |
$dbi->update_all(table => $table, |
... | ... |
@@ -1046,6 +1046,11 @@ You can set column names |
1046 | 1046 |
|
1047 | 1047 |
$model->columns(['id', 'number_id']); |
1048 | 1048 |
|
1049 |
+Column names is automarically set by C<setup_model()>. |
|
1050 |
+This method is needed to be call after C<include_model()>. |
|
1051 |
+ |
|
1052 |
+ $dbi->setup_model; |
|
1053 |
+ |
|
1049 | 1054 |
=head2 Model Examples |
1050 | 1055 |
|
1051 | 1056 |
Model examples |
... | ... |
@@ -1074,6 +1074,11 @@ C<select_at()>で利用されます。 |
1074 | 1074 |
|
1075 | 1075 |
$model->columns(['id', 'number_id']); |
1076 | 1076 |
|
1077 |
+列名はC<setup_model()>で自動的に設定することができます。 |
|
1078 |
+このメソッドはC<include_model()>の後で呼び出してください。 |
|
1079 |
+ |
|
1080 |
+ $dbi->setup_model; |
|
1081 |
+ |
|
1077 | 1082 |
=head2 モデルのサンプル |
1078 | 1083 |
|
1079 | 1084 |
モデルのサンプルです。 |
... | ... |
@@ -1385,3 +1385,12 @@ $model = $dbi->model('book'); |
1385 | 1385 |
$model->columns(['id', 'number']); |
1386 | 1386 |
is_deeply($model->columns, ['id', 'number']); |
1387 | 1387 |
|
1388 |
+test 'setup_model'; |
|
1389 |
+use MyDBI1; |
|
1390 |
+$dbi = MyDBI1->connect($NEW_ARGS->{0}); |
|
1391 |
+$dbi->execute('create table book (id)'); |
|
1392 |
+$dbi->execute('create table company (id, name);'); |
|
1393 |
+$dbi->execute('create table test (id, name, primary key (id, name));'); |
|
1394 |
+$dbi->setup_model; |
|
1395 |
+is_deeply($dbi->model('book')->columns, ['id']); |
|
1396 |
+is_deeply($dbi->model('company')->columns, ['id', 'name']); |