... | ... |
@@ -1,3 +1,5 @@ |
1 |
+0.1648 |
|
2 |
+ add models() attribute |
|
1 | 3 |
0.1647 |
2 | 4 |
add default_dbi_option() |
3 | 5 |
0.1646 |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
package DBIx::Custom; |
2 | 2 |
|
3 |
-our $VERSION = '0.1647'; |
|
3 |
+our $VERSION = '0.1648'; |
|
4 | 4 |
|
5 | 5 |
use 5.008001; |
6 | 6 |
use strict; |
... | ... |
@@ -27,6 +27,7 @@ __PACKAGE__->attr( |
27 | 27 |
PrintError => 0, |
28 | 28 |
AutoCommit => 1 |
29 | 29 |
}}, |
30 |
+ models => sub { {} }, |
|
30 | 31 |
query_builder => sub { DBIx::Custom::QueryBuilder->new }, |
31 | 32 |
result_class => 'DBIx::Custom::Result', |
32 | 33 |
safety_column_name => sub { qr/^[\w\.]*$/ }, |
... | ... |
@@ -597,18 +598,17 @@ sub model { |
597 | 598 |
my ($self, $name, $model) = @_; |
598 | 599 |
|
599 | 600 |
# Set |
600 |
- $self->{model} ||= {}; |
|
601 | 601 |
if ($model) { |
602 |
- $self->{model}{$name} = $model; |
|
602 |
+ $self->models->{$name} = $model; |
|
603 | 603 |
return $self; |
604 | 604 |
} |
605 | 605 |
|
606 | 606 |
# Check model existance |
607 | 607 |
croak qq{Model "$name" is not included} |
608 |
- unless $self->{model}{$name}; |
|
608 |
+ unless $self->models->{$name}; |
|
609 | 609 |
|
610 | 610 |
# Get |
611 |
- return $self->{model}{$name}; |
|
611 |
+ return $self->models->{$name}; |
|
612 | 612 |
} |
613 | 613 |
|
614 | 614 |
sub include_model { |
... | ... |
@@ -1054,6 +1054,15 @@ Default filter when row is fetched. |
1054 | 1054 |
my $filters = $dbi->filters; |
1055 | 1055 |
$dbi = $dbi->filters(\%filters); |
1056 | 1056 |
|
1057 |
+Filters |
|
1058 |
+ |
|
1059 |
+=head2 C<(experimental) models> |
|
1060 |
+ |
|
1061 |
+ my $models = $dbi->models; |
|
1062 |
+ $dbi = $dbi->models(\%models); |
|
1063 |
+ |
|
1064 |
+Models |
|
1065 |
+ |
|
1057 | 1066 |
=head2 C<password> |
1058 | 1067 |
|
1059 | 1068 |
my $password = $dbi->password; |
... | ... |
@@ -1031,6 +1031,10 @@ You can also call all methods of L<DBIx::Custom> and L<DBI>. |
1031 | 1031 |
$model->begin_work; |
1032 | 1032 |
$model->commit; |
1033 | 1033 |
|
1034 |
+If you want to get all models, you can get them by keys of C<models()>. |
|
1035 |
+ |
|
1036 |
+ my @models = keys %{$self->models}; |
|
1037 |
+ |
|
1034 | 1038 |
=head2 Model Examples |
1035 | 1039 |
|
1036 | 1040 |
Model examples |
... | ... |
@@ -1059,6 +1059,10 @@ L<DBIx::Custom>とL<DBI>のすべてのメソッドを呼び出すこともで |
1059 | 1059 |
$model->begin_work; |
1060 | 1060 |
$model->commit; |
1061 | 1061 |
|
1062 |
+すべてのモデル名を取得したい場合はC<models()>のキーを取得してください。 |
|
1063 |
+ |
|
1064 |
+ my @models = keys %{$self->models}; |
|
1065 |
+ |
|
1062 | 1066 |
=head2 モデルのサンプル |
1063 | 1067 |
|
1064 | 1068 |
モデルのサンプルです。 |
... | ... |
@@ -1276,6 +1276,8 @@ $dbi->execute("create table company (name)"); |
1276 | 1276 |
$model = $dbi->model('company'); |
1277 | 1277 |
$model->insert({name => 'a'}); |
1278 | 1278 |
is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'basic'); |
1279 |
+is($dbi->models->{'book'}, $dbi->model('book')); |
|
1280 |
+is($dbi->models->{'company'}, $dbi->model('company')); |
|
1279 | 1281 |
|
1280 | 1282 |
$dbi->model('book'); |
1281 | 1283 |
eval{$dbi->model('book')->no_exists}; |