Showing 7 changed files with 54 additions and 4 deletions
+2 -1
Changes
... ...
@@ -1,6 +1,7 @@
1
+0.1651
2
+    - add experimental DBIx::Custom::Model filter attribute.
1 3
 0.1650
2 4
     - add experimental DBIx::Custom::Model name() attribute
3
-    - remove name specified feature from experimantal include_model().
4 5
 0.1649
5 6
     - add experimental DBIx::Custom::Model column_clause() method.
6 7
     - select method column option can receive string.
+4 -1
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1650';
3
+our $VERSION = '0.1651';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -771,6 +771,9 @@ sub include_model {
771 771
         
772 772
         # Set
773 773
         $self->model($model->name, $model);
774
+        
775
+        # Apply filter
776
+        $self->apply_filter($model->table, %{$model->filter});
774 777
     }
775 778
     return $self;
776 779
 }
+9
lib/DBIx/Custom/Guide.pod
... ...
@@ -1084,6 +1084,15 @@ You can set primary key to model.
1084 1084
 Primary key is used by C<update_at()>, C<delete_at()>,
1085 1085
 C<select_at()>.
1086 1086
 
1087
+by C<filter> you can define filters applied by C<apply_filter()>
1088
+
1089
+    $model->filter({
1090
+        title  => {out => ..., in => ..., end => ...},
1091
+        author => {out => ..., in => ..., end => ...}
1092
+    });
1093
+
1094
+This filters is applied when C<include_model()> is called.
1095
+
1087 1096
 You can set column names
1088 1097
 
1089 1098
     $model->columns(['id', 'number_id']);
+15 -1
lib/DBIx/Custom/Guide/Ja.pod
... ...
@@ -1119,6 +1119,15 @@ L<DBIx::Custom>とL<DBI>のすべてのメソッドを呼び出すこともで
1119 1119
 ここで設定したプライマリーキーはC<update_at()>, C<delete_at()>,
1120 1120
 C<select_at()>で利用されます。
1121 1121
 
1122
+C<filter>でC<apply_filter()>で適用されるフィルタを定義しておくこともできます。
1123
+
1124
+    $model->filter({
1125
+        title  => {out => ..., in => ..., end => ...},
1126
+        author => {out => ..., in => ..., end => ...}
1127
+    });
1128
+
1129
+このフィルタはC<include_model()>を呼び出したときに自動的に適用されます。
1130
+
1122 1131
 モデルには列名を設定することもできます。
1123 1132
 
1124 1133
     $model->columns(['id', 'number_id']);
... ...
@@ -1134,6 +1143,7 @@ C<select_at()>で利用されます。
1134 1143
 
1135 1144
 ここで設定したリレーションはC<select()>, C<select_at()>で利用されます。
1136 1145
 
1146
+
1137 1147
 =head2 クラス名、モデル名、テーブル名
1138 1148
 
1139 1149
 クラス名とモデル名とテーブル名の関係について書いておきます。
... ...
@@ -1146,6 +1156,8 @@ C<select_at()>で利用されます。
1146 1156
 
1147 1157
     package MyModel::book;
1148 1158
     
1159
+    use base 'MyModel';
1160
+    
1149 1161
     __PACAKGE__->attr(name => 'book_model');
1150 1162
 
1151 1163
     クラス名     モデル名      テーブル名
... ...
@@ -1158,9 +1170,11 @@ C<select_at()>で利用されます。
1158 1170
 テーブル名を変更することもできます。
1159 1171
 
1160 1172
     package MyModel::book;
1173
+
1174
+    use base 'MyModel';
1161 1175
     
1162 1176
     __PACAKGE__->attr(table => 'book_table');
1163
-
1177
+    
1164 1178
     クラス名     モデル名              テーブル名
1165 1179
     book         (クラス名) -> book    book_table
1166 1180
 
+9 -1
lib/DBIx/Custom/Model.pm
... ...
@@ -13,6 +13,7 @@ push @DBIx::Custom::CARP_NOT, __PACKAGE__;
13 13
 __PACKAGE__->attr(
14 14
     ['dbi', 'name', 'table'],
15 15
     columns => sub { [] },
16
+    filter => sub { {} },
16 17
     primary_key => sub { [] },
17 18
     relation => sub { {} }
18 19
 );
... ...
@@ -157,7 +158,7 @@ my $table = DBIx::Custom::Model->new(table => 'books');
157 158
 
158 159
 =head1 ATTRIBUTES
159 160
 
160
-=head2 C<(experimental) columns>
161
+=head2 C<columns>
161 162
 
162 163
     my $columns = $model->columns;
163 164
     $model      = $model->columns(['id', 'number']);
... ...
@@ -169,6 +170,13 @@ my $table = DBIx::Custom::Model->new(table => 'books');
169 170
 
170 171
 L<DBIx::Custom> object.
171 172
 
173
+=head2 C<filter>
174
+
175
+    my $dbi = $model->filter
176
+    $model  = $model->filter({out => 'tp_to_date', in => 'date_to_tp'});
177
+
178
+This filter is applied when L<DBIx::Custom> C<include_model()> is called.
179
+
172 180
 =head2 C<name>
173 181
 
174 182
     my $name = $model->name;
+4
t/dbix-custom-core-sqlite.t
... ...
@@ -1591,6 +1591,10 @@ $result = $dbi->model('table1')->select(column => ['key3'], where => {'table1.ke
1591 1591
 is($result->fetch_hash_first->{key3}, 3);
1592 1592
 $result = $dbi->model('table1')->select_at(column => ['key3'], where => [1]);
1593 1593
 is($result->fetch_hash_first->{key3}, 3);
1594
+$dbi->execute('create table table3 (key1);');
1595
+$dbi->model('table3')->insert(param => {key1 => 'a'});
1596
+is_deeply($dbi->model('table3')->select(where => {key1 => 'a'})->fetch_hash_first,
1597
+   {key1 => 'A'});
1594 1598
 
1595 1599
 test 'column_clause';
1596 1600
 $dbi = MyDBI7->connect($NEW_ARGS->{0});
+11
t/dbix-custom-core-sqlite/MyModel6/table3.pm
... ...
@@ -0,0 +1,11 @@
1
+package MyModel6::table3;
2
+
3
+use base 'MyModel6';
4
+
5
+__PACKAGE__->attr(filter => sub {
6
+    {
7
+        key1 => {in => sub { uc $_[0] }}
8
+    }
9
+});
10
+
11
+1;