Showing 3 changed files with 37 additions and 12 deletions
+2
Changes
... ...
@@ -1,3 +1,5 @@
1
+0.26
2
+  - fixed bug that when id option's value is object, don't work.
1 3
 0.25
2 4
   - added DBIX_CUSTOM_SUPPRESS_DEPRECATION environment varaible
3 5
     to suppress deprecation warnings
+9 -9
lib/DBIx/Custom.pm
... ...
@@ -2,7 +2,7 @@ use 5.008007;
2 2
 package DBIx::Custom;
3 3
 use Object::Simple -base;
4 4
 
5
-our $VERSION = '0.25';
5
+our $VERSION = '0.26';
6 6
 
7 7
 use Carp 'croak';
8 8
 use DBI;
... ...
@@ -461,8 +461,8 @@ sub execute {
461 461
       unless $statement;
462 462
     croak "execute id option must be specified with primary_key option"
463 463
       unless $opt{primary_key};
464
-    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
465
-    $opt{id} = [$opt{id}] unless ref $opt{id};
464
+    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key} eq 'ARRAY';
465
+    $opt{id} = [$opt{id}] unless ref $opt{id} eq 'ARRAY';
466 466
     for (my $i = 0; $i < @{$opt{id}}; $i++) {
467 467
       my $key = $opt{primary_key}->[$i];
468 468
       $key = "$main_table.$key" if $statement eq 'update' ||
... ...
@@ -732,8 +732,8 @@ sub insert {
732 732
   if (defined $opt{id} && !$multi) {
733 733
     croak "insert id option must be specified with primary_key option"
734 734
       unless $opt{primary_key};
735
-    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
736
-    $opt{id} = [$opt{id}] unless ref $opt{id};
735
+    $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key} eq 'ARRAY';
736
+    $opt{id} = [$opt{id}] unless ref $opt{id} eq 'ARRAY';
737 737
     for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
738 738
       my $key = $opt{primary_key}->[$i];
739 739
       next if exists $params->[0]->{$key};
... ...
@@ -851,8 +851,8 @@ sub include_model {
851 851
     my $mclass = "${name_space}::$model_class";
852 852
     croak qq{"$mclass" is invalid class name } . _subname
853 853
       if $mclass =~ /[^\w:]/;
854
-    unless ($mclass->can('isa')) {
855
-      eval "use $mclass";
854
+    unless ($mclass->can('new')) {
855
+      eval "require $mclass";
856 856
       croak "$@ " . _subname if $@;
857 857
     }
858 858
     
... ...
@@ -1562,7 +1562,7 @@ sub _id_to_param {
1562 1562
   # Create parameter
1563 1563
   my $param = {};
1564 1564
   if (defined $id) {
1565
-    $id = [$id] unless ref $id;
1565
+    $id = [$id] unless ref $id eq 'ARRAY';
1566 1566
     for(my $i = 0; $i < @$id; $i++) {
1567 1567
       my $key = $primary_keys->[$i];
1568 1568
       $key = "$table." . $key if $table;
... ...
@@ -2016,7 +2016,7 @@ sub insert_at {
2016 2016
   $param = shift if @_ % 2;
2017 2017
   my %opt = @_;
2018 2018
   my $primary_key = delete $opt{primary_key};
2019
-  $primary_key = [$primary_key] unless ref $primary_key;
2019
+  $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
2020 2020
   my $where = delete $opt{where};
2021 2021
   my $p = delete $opt{param} || {};
2022 2022
   $param  ||= $p;
+26 -3
t/common.t
... ...
@@ -2818,6 +2818,16 @@ is($dbi->select(table => $table1)->one->{$key1}, 1);
2818 2818
 is($dbi->select(table => $table1)->one->{$key2}, 2);
2819 2819
 is($dbi->select(table => $table1)->one->{$key3}, 3);
2820 2820
 
2821
+$dbi->insert(
2822
+  {$key3 => 3},
2823
+  primary_key => [$key1, $key2], 
2824
+  table => $table1,
2825
+  id => [1, 2],
2826
+);
2827
+is($dbi->select(table => $table1)->one->{$key1}, 1);
2828
+is($dbi->select(table => $table1)->one->{$key2}, 2);
2829
+is($dbi->select(table => $table1)->one->{$key3}, 3);
2830
+
2821 2831
 $dbi->delete_all(table => $table1);
2822 2832
 $dbi->insert(
2823 2833
   {$key2 => 2, $key3 => 3},
... ...
@@ -2830,6 +2840,19 @@ is($dbi->select(table => $table1)->one->{$key1}, 0);
2830 2840
 is($dbi->select(table => $table1)->one->{$key2}, 2);
2831 2841
 is($dbi->select(table => $table1)->one->{$key3}, 3);
2832 2842
 
2843
+$dbi = DBIx::Custom->connect;
2844
+eval { $dbi->execute("drop table $table1") };
2845
+$dbi->execute($create_table1_2);
2846
+$dbi->insert(
2847
+  {$key3 => 3},
2848
+  primary_key => $key1, 
2849
+  table => $table1,
2850
+  id => bless({value => 1}, 'AAAA'),
2851
+  filter => {$key1 => sub { shift->{value} }}
2852
+);
2853
+is($dbi->select(table => $table1)->one->{$key1}, 1);
2854
+is($dbi->select(table => $table1)->one->{$key3}, 3);
2855
+
2833 2856
 $dbi = DBIx::Custom->connect;
2834 2857
 eval { $dbi->execute("drop table $table1") };
2835 2858
 $dbi->execute($create_table1_2);
... ...
@@ -3868,10 +3891,10 @@ $dbi->register_tag(
3868 3891
 
3869 3892
 test 'Default tag Error case';
3870 3893
 eval{$builder->build_query("{= }")};
3871
-like($@, qr/Column name must be specified in tag "{= }"/, "basic '=' : key not exist");
3894
+like($@, qr/\QColumn name must be specified in tag "{= }"/, "basic '=' : key not exist");
3872 3895
 
3873 3896
 eval{$builder->build_query("{in }")};
3874
-like($@, qr/Column name and count of values must be specified in tag "{in }"/, "in : key not exist");
3897
+like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/, "in : key not exist");
3875 3898
 
3876 3899
 eval{$builder->build_query("{in a}")};
3877 3900
 like($@, qr/\QColumn name and count of values must be specified in tag "{in }"/,
... ...
@@ -3904,7 +3927,7 @@ like($@, qr/unexpected "}"/, "error : 1");
3904 3927
 
3905 3928
 $source = "a {= {}";
3906 3929
 eval{$builder->build_query($source)};
3907
-like($@, qr/unexpected "{"/, "error : 2");
3930
+like($@, qr/\Qunexpected "{"/, "error : 2");
3908 3931
 
3909 3932
 test 'select() sqlfilter option';
3910 3933
 $dbi = DBIx::Custom->connect;