| ... | ... |
@@ -306,13 +306,6 @@ sub create_model {
|
| 306 | 306 |
? [%{$model->filter}]
|
| 307 | 307 |
: $model->filter; |
| 308 | 308 |
$self->_apply_filter($model->table, @$filter); |
| 309 |
- my $result_filter = ref $model->result_filter eq 'HASH' |
|
| 310 |
- ? [%{$model->result_filter}]
|
|
| 311 |
- : $model->result_filter; |
|
| 312 |
- for (my $i = 1; $i < @$result_filter; $i += 2) {
|
|
| 313 |
- $result_filter->[$i] = {in => $result_filter->[$i]};
|
|
| 314 |
- } |
|
| 315 |
- $self->_apply_filter($model->table, @$result_filter); |
|
| 316 | 309 |
|
| 317 | 310 |
# Associate table with model |
| 318 | 311 |
croak "Table name is duplicated " . _subname |
| ... | ... |
@@ -1449,8 +1442,8 @@ sub apply_filter {
|
| 1449 | 1442 |
my $self = shift; |
| 1450 | 1443 |
|
| 1451 | 1444 |
warn "apply_filter is DEPRECATED! " . |
| 1452 |
- "use type_rule method, DBIx::Custom::Result filter method, " . |
|
| 1453 |
- "and DBIx::Custom::Model result_filter method instead"; |
|
| 1445 |
+ "use type_rule method and DBIx::Custom::Result filter method, " . |
|
| 1446 |
+ "instead"; |
|
| 1454 | 1447 |
|
| 1455 | 1448 |
return $self->_apply_filter(@_); |
| 1456 | 1449 |
} |
| ... | ... |
@@ -12,7 +12,6 @@ has [qw/dbi name table view/], |
| 12 | 12 |
table_alias => sub { {} },
|
| 13 | 13 |
columns => sub { [] },
|
| 14 | 14 |
filter => sub { [] },
|
| 15 |
- result_filter => sub { [] },
|
|
| 16 | 15 |
join => sub { [] },
|
| 17 | 16 |
type => sub { [] },
|
| 18 | 17 |
primary_key => sub { [] };
|
| ... | ... |
@@ -173,16 +172,6 @@ Join clause, this is used as C<select()>'s C<join> option. |
| 173 | 172 |
Foreign key, this is used as C<primary_key> of C<insert_at>,C<update_at()>, |
| 174 | 173 |
C<delete_at()>,C<select_at()>. |
| 175 | 174 |
|
| 176 |
-=head2 C<result_filter> EXPERIMENTAL |
|
| 177 |
- |
|
| 178 |
- my $dbi = $model->result_filter |
|
| 179 |
- $model = $model->result_filter( |
|
| 180 |
- title => sub { ... },
|
|
| 181 |
- author => sub { ... }
|
|
| 182 |
- ); |
|
| 183 |
- |
|
| 184 |
-This filter is applied when L<DBIx::Custom>'s C<include_model()> or C<create_model> is called. |
|
| 185 |
- |
|
| 186 | 175 |
=head2 C<table> |
| 187 | 176 |
|
| 188 | 177 |
my $table = $model->table; |
| ... | ... |
@@ -2863,13 +2863,10 @@ $dbi->type_rule( |
| 2863 | 2863 |
); |
| 2864 | 2864 |
$dbi->insert({key1 => 2}, table => 'table1');
|
| 2865 | 2865 |
$result = $dbi->select(table => 'table1'); |
| 2866 |
-$result->filter(key1 => sub { $_[0] * 3});
|
|
| 2866 |
+$result->filter(key1 => sub { $_[0] * 3 });
|
|
| 2867 | 2867 |
is($result->one->{key1}, 6);
|
| 2868 |
-$result = $dbi->select(table => 'table1'); |
|
| 2869 |
-$result->filter(key1 => sub { $_[0] * 3});
|
|
| 2870 |
-is($result->fetch->[0], 6); |
|
| 2871 | 2868 |
|
| 2872 |
-test 'result_filter'; |
|
| 2869 |
+test 'separator'; |
|
| 2873 | 2870 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|
| 2874 | 2871 |
$dbi->execute($CREATE_TABLE->{0});
|
| 2875 | 2872 |
$dbi->execute($CREATE_TABLE->{2});
|
| ... | ... |
@@ -2880,15 +2877,9 @@ $dbi->create_model( |
| 2880 | 2877 |
'left outer join table2 on table1.key1 = table2.key1' |
| 2881 | 2878 |
], |
| 2882 | 2879 |
primary_key => ['key1'], |
| 2883 |
- result_filter => {
|
|
| 2884 |
- key1 => sub { $_[0] * 2 }
|
|
| 2885 |
- } |
|
| 2886 | 2880 |
); |
| 2887 | 2881 |
$model2 = $dbi->create_model( |
| 2888 | 2882 |
table => 'table2', |
| 2889 |
- result_filter => [ |
|
| 2890 |
- [qw/key1 key3/] => sub { $_[0] * 3 }
|
|
| 2891 |
- ] |
|
| 2892 | 2883 |
); |
| 2893 | 2884 |
$dbi->setup_model; |
| 2894 | 2885 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| ... | ... |
@@ -2902,8 +2893,8 @@ $result = $model->select( |
| 2902 | 2893 |
where => {'table1.key1' => 1}
|
| 2903 | 2894 |
); |
| 2904 | 2895 |
is_deeply($result->one, |
| 2905 |
- {key1 => 2, key2 => 2, 'table2.key1' => 3, 'table2.key3' => 9});
|
|
| 2906 |
-is_deeply($model2->select->one, {key1 => 3, key3 => 9});
|
|
| 2896 |
+ {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
|
|
| 2897 |
+is_deeply($model2->select->one, {key1 => 1, key3 => 3});
|
|
| 2907 | 2898 |
|
| 2908 | 2899 |
$dbi->separator('__');
|
| 2909 | 2900 |
$model = $dbi->model('table1');
|
| ... | ... |
@@ -2915,8 +2906,8 @@ $result = $model->select( |
| 2915 | 2906 |
where => {'table1.key1' => 1}
|
| 2916 | 2907 |
); |
| 2917 | 2908 |
is_deeply($result->one, |
| 2918 |
- {key1 => 2, key2 => 2, 'table2__key1' => 3, 'table2__key3' => 9});
|
|
| 2919 |
-is_deeply($model2->select->one, {key1 => 3, key3 => 9});
|
|
| 2909 |
+ {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
|
|
| 2910 |
+is_deeply($model2->select->one, {key1 => 1, key3 => 3});
|
|
| 2920 | 2911 |
|
| 2921 | 2912 |
$dbi->separator('-');
|
| 2922 | 2913 |
$model = $dbi->model('table1');
|
| ... | ... |
@@ -2928,8 +2919,8 @@ $result = $model->select( |
| 2928 | 2919 |
where => {'table1.key1' => 1}
|
| 2929 | 2920 |
); |
| 2930 | 2921 |
is_deeply($result->one, |
| 2931 |
- {key1 => 2, key2 => 2, 'table2-key1' => 3, 'table2-key3' => 9});
|
|
| 2932 |
-is_deeply($model2->select->one, {key1 => 3, key3 => 9});
|
|
| 2922 |
+ {key1 => 1, key2 => 2, 'table2-key1' => 1, 'table2-key3' => 3});
|
|
| 2923 |
+is_deeply($model2->select->one, {key1 => 1, key3 => 3});
|
|
| 2933 | 2924 |
|
| 2934 | 2925 |
|
| 2935 | 2926 |
test 'filter_off'; |
| ... | ... |
@@ -2943,45 +2934,13 @@ $dbi->create_model( |
| 2943 | 2934 |
'left outer join table2 on table1.key1 = table2.key1' |
| 2944 | 2935 |
], |
| 2945 | 2936 |
primary_key => ['key1'], |
| 2946 |
- result_filter => {
|
|
| 2947 |
- key1 => sub { $_[0] * 2 }
|
|
| 2948 |
- }, |
|
| 2949 |
-); |
|
| 2950 |
-$model2 = $dbi->create_model( |
|
| 2951 |
- table => 'table2', |
|
| 2952 |
- result_filter => [ |
|
| 2953 |
- [qw/key1 key3/] => sub { $_[0] * 3 }
|
|
| 2954 |
- ] |
|
| 2955 | 2937 |
); |
| 2956 | 2938 |
$dbi->setup_model; |
| 2957 | 2939 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
| 2958 |
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
|
|
| 2959 | 2940 |
$model = $dbi->model('table1');
|
| 2960 |
-$result = $model->select( |
|
| 2961 |
- column => [ |
|
| 2962 |
- $model->mycolumn, |
|
| 2963 |
- {table2 => [qw/key1 key3/]}
|
|
| 2964 |
- ], |
|
| 2965 |
- where => {'table1.key1' => 1}
|
|
| 2966 |
-); |
|
| 2967 |
-$result->filter_off(1); |
|
| 2968 |
-$result->end_filter(key1 => sub { $_[0] * 5});
|
|
| 2969 |
-is_deeply($result->one, |
|
| 2970 |
- {key1 => 1, key2 => 2, 'table2.key1' => 1, 'table2.key3' => 3});
|
|
| 2971 |
- |
|
| 2972 |
-$result = $model->select( |
|
| 2973 |
- column => [ |
|
| 2974 |
- $model->mycolumn, |
|
| 2975 |
- {table2 => [qw/key1 key3/]}
|
|
| 2976 |
- ], |
|
| 2977 |
- where => {'table1.key1' => 1}
|
|
| 2978 |
-); |
|
| 2979 |
-$result->filter_off(1); |
|
| 2980 |
-$result->end_filter(key1 => sub { $_[0] * 5});
|
|
| 2981 |
- |
|
| 2982 |
-is_deeply($result->fetch_first, |
|
| 2983 |
- [1, 2, 1, 3]); |
|
| 2984 |
- |
|
| 2941 |
+$result = $model->select(column => 'key1'); |
|
| 2942 |
+$result->filter(key1 => sub { $_[0] * 2 });
|
|
| 2943 |
+is_deeply($result->one, {key1 => 2});
|
|
| 2985 | 2944 |
|
| 2986 | 2945 |
test 'available_date_type'; |
| 2987 | 2946 |
$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
|