Showing 1 changed files with 18 additions and 30 deletions
+18 -30
lib/DBIx/Custom.pm
... ...
@@ -329,49 +329,38 @@ sub execute {
329 329
     $self->last_sql($query->sql);
330 330
 
331 331
     return $query if $query_return;
332
+    
333
+    # DEPRECATED! Merge query filter
332 334
     $filter ||= $query->{filter} || {};
333 335
     
334 336
     # Tables
335 337
     unshift @$tables, @{$query->{tables} || []};
336 338
     my $main_table = @{$tables}[-1];
337 339
     
338
-    # DEPRECATED!
340
+    # DEPRECATED! Cleanup tables
339 341
     $tables = $self->_remove_duplicate_table($tables, $main_table)
340 342
       if @$tables > 1;
341 343
     
342 344
     # Type rule
343 345
     my $type_filters = {};
344 346
     unless ($type_rule_off) {
345
-        foreach my $name (keys %$param) {
346
-            my $table;
347
-            my $column;
348
-            if ($name =~ /(?:(.+)\.)?(.+)/) {
349
-                $table = $1;
350
-                $column = $2;
351
-            }
352
-            $table ||= $main_table;
353
-            
354
-            foreach my $i (1 .. 2) {
355
-                unless ($type_rule_off_parts->{$i}) {
356
-                    my $into = $self->{"_into$i"} || {};
357
-                    
358
-                    my $alias = $table;
359
-                    $table = $table_alias->{$alias}
360
-                      if defined $alias && $table_alias->{$alias};
347
+        foreach my $i (1, 2) {
348
+            unless ($type_rule_off_parts->{$i}) {
349
+                $type_filters->{$i} = {};
350
+                foreach my $alias (keys %$table_alias) {
351
+                    my $table = $table_alias->{$alias};
361 352
                     
362
-                    if (defined $table && $into->{$table} &&
363
-                        (my $rule = $into->{$table}->{$column}))
364
-                    {
365
-                        $type_filters->{$i}->{$column} = $rule;
366
-                        $type_filters->{$i}->{"$table.$column"} = $rule;
367
-                        $type_filters->{$i}->{"$alias.$column"} = $rule if $alias ne $table;
353
+                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
354
+                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
368 355
                     }
369 356
                 }
357
+                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
358
+                  if $main_table;
370 359
             }
371 360
         }
372 361
     }
373 362
     
374
-    # Applied filter(DEPRECATED!)
363
+    # DEPRECATED! Applied filter
375 364
     if ($self->{filter}{on}) {
376 365
         my $applied_filter = {};
377 366
         foreach my $table (@$tables) {
... ...
@@ -420,10 +409,8 @@ sub execute {
420 409
         $affected = $sth->execute;
421 410
     };
422 411
     
423
-    if ($@) {
424
-        $self->_croak($@, qq{. Following SQL is executed.\n}
425
-                        . qq{$query->{sql}\n} . _subname);
426
-    }
412
+    $self->_croak($@, qq{. Following SQL is executed.\n}
413
+      . qq{$query->{sql}\n} . _subname) if $@;
427 414
     
428 415
     # DEBUG message
429 416
     if (DEBUG) {
... ...
@@ -980,7 +967,8 @@ sub type_rule {
980 967
                         $filter = $self->filters->{$fname};
981 968
                     }
982 969
 
983
-                    $self->{"_$into"}{$table}{$column} = $filter;
970
+                    $self->{"_$into"}{key}{$table}{$column} = $filter;
971
+                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
984 972
                 }
985 973
             });
986 974
         }
... ...
@@ -1201,7 +1189,7 @@ sub _create_bind_values {
1201 1189
         # Type rule
1202 1190
         foreach my $i (1 .. 2) {
1203 1191
             my $type_filter = $type_filters->{$i};
1204
-            my $tf = $type_filter->{$column};
1192
+            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
1205 1193
             $value = $tf->($value) if $tf;
1206 1194
         }
1207 1195