Showing 1 changed files with 15 additions and 34 deletions
+15 -34
lib/DBIx/Custom.pm
... ...
@@ -968,10 +968,10 @@ sub select_at {
968 968
 sub setup_model {
969 969
     my $self = shift;
970 970
     
971
+    # Setup model
971 972
     $self->each_column(
972 973
         sub {
973 974
             my ($self, $table, $column, $column_info) = @_;
974
-            
975 975
             if (my $model = $self->models->{$table}) {
976 976
                 push @{$model->columns}, $column;
977 977
             }
... ...
@@ -986,15 +986,6 @@ our %UPDATE_ARGS
986 986
 sub update {
987 987
     my ($self, %args) = @_;
988 988
 
989
-    # Reserved word quote
990
-    my $q = $self->reserved_word_quote;
991
-    
992
-    # Check argument names
993
-    foreach my $name (keys %args) {
994
-        croak qq{Argument "$name" is wrong name}
995
-          unless $UPDATE_ARGS{$name};
996
-    }
997
-    
998 989
     # Arguments
999 990
     my $table = delete $args{table} || '';
1000 991
     croak qq{"table" option must be specified} unless $table;
... ...
@@ -1003,9 +994,16 @@ sub update {
1003 994
     my $append           = delete $args{append} || '';
1004 995
     my $allow_update_all = delete $args{allow_update_all};
1005 996
     
997
+    # Check argument names
998
+    foreach my $name (keys %args) {
999
+        croak qq{Argument "$name" is wrong name}
1000
+          unless $UPDATE_ARGS{$name};
1001
+    }
1002
+    
1006 1003
     # Columns
1007 1004
     my @columns;
1008 1005
     my $safety = $self->safety_character;
1006
+    my $q = $self->reserved_word_quote;
1009 1007
     foreach my $column (keys %$param) {
1010 1008
         croak qq{"$column" is not safety column name}
1011 1009
           unless $column =~ /^[$safety\.]+$/;
... ...
@@ -1018,35 +1016,18 @@ sub update {
1018 1016
     my $update_clause = '{update_param ' . join(' ', @columns) . '}';
1019 1017
 
1020 1018
     # Where
1021
-    my $w = $self->_where_to_obj($where);
1022
-    $where = $w->param;
1023
-    
1024
-    # String where
1025
-    my $swhere = "$w";
1026
-    
1019
+    $where = $self->_where_to_obj($where);
1020
+    my $where_clause = $where->to_string;
1027 1021
     croak qq{"where" must be specified}
1028
-      if "$swhere" eq '' && !$allow_update_all;
1022
+      if "$where_clause" eq '' && !$allow_update_all;
1029 1023
     
1030
-    # SQL stack
1024
+    # Update statement
1031 1025
     my @sql;
1032
-    
1033
-    # Update
1034
-    push @sql, "update $q$table$q $update_clause $swhere";
1026
+    push @sql, "update $q$table$q $update_clause $where_clause";
1035 1027
     push @sql, $append if $append;
1036 1028
     
1037
-    # Rearrange parameters
1038
-    foreach my $wkey (keys %$where) {
1039
-        
1040
-        if (exists $param->{$wkey}) {
1041
-            $param->{$wkey} = [$param->{$wkey}]
1042
-              unless ref $param->{$wkey} eq 'ARRAY';
1043
-            
1044
-            push @{$param->{$wkey}}, $where->{$wkey};
1045
-        }
1046
-        else {
1047
-            $param->{$wkey} = $where->{$wkey};
1048
-        }
1049
-    }
1029
+    # Merge parameters
1030
+    $param = $self->merge_param($param, $where->param);
1050 1031
     
1051 1032
     # SQL
1052 1033
     my $sql = join(' ', @sql);