Showing 5 changed files with 20 additions and 23 deletions
+9 -11
lib/DBIx/Custom.pm
... ...
@@ -1126,11 +1126,16 @@ sub setup_model {
1126 1126
     sub {
1127 1127
       my ($self, $table, $column, $column_info) = @_;
1128 1128
       my $schema = $column_info->{TABLE_SCHEM};
1129
-      return if exists $opt{schema} && $opt{schema} ne $schema;
1130 1129
       
1131
-      $table = "$schema.$table" if exists $opt{prefix};
1130
+      my $default_schema = $self->default_schema;
1131
+      
1132 1132
       if (my $model = $self->models->{$table}) {
1133
-        push @{$model->columns}, $column;
1133
+        if (!defined $default_schema || $default_schema eq $schema) {
1134
+          push @{$model->columns}, $column;
1135
+        }
1136
+      }
1137
+      if (my $fullqualified_model = $self->models->{"$schema.$table"}) {
1138
+        push @{$fullqualified_model->columns}, $column;
1134 1139
       }
1135 1140
     }
1136 1141
   );
... ...
@@ -1218,7 +1223,7 @@ sub type_rule {
1218 1223
           
1219 1224
           my $schema = $column_info->{TABLE_SCHEM};
1220 1225
           my $default_schema = $self->default_schema;
1221
-          if (!defined $default_schema || (defined $default_schema && $default_schema eq $schema)) {
1226
+          if (!defined $default_schema || $default_schema eq $schema) {
1222 1227
             $self->{"_$into"}{key}{$table}{$column} = $filter;
1223 1228
             $self->{"_$into"}{dot}{"$table.$column"} = $filter;
1224 1229
           }
... ...
@@ -3431,17 +3436,10 @@ See also L<DBIx::Custom::Where> to know how to create where clause.
3431 3436
 =head2 C<setup_model>
3432 3437
 
3433 3438
   $dbi->setup_model;
3434
-  $dbi->setup_model(schema => 'main');
3435
-  $dbi->setup_model(schema => 'main', prefix => 1);
3436 3439
 
3437 3440
 Setup all model objects.
3438 3441
 C<columns> of model object is automatically set, parsing database information.
3439 3442
 
3440
-If C<database> option is specified, only the database is searched.
3441
-
3442
-If C<prefix> option is specified, Target model is qualified by dabtabase name
3443
-like C<main.book>.
3444
-
3445 3443
 =head2 C<type_rule>
3446 3444
 
3447 3445
   $dbi->type_rule(
+1 -1
t/common-mysql-fullqualified.t
... ...
@@ -43,7 +43,7 @@ use DBIx::Custom;
43 43
   has key8 => $key8;
44 44
   has key9 => $key9;
45 45
   has key10 => $key10;
46
-  has setup_model_args => sub { [database => 'dbix_custom', prefix => 1] };
46
+  has default_schema => 'dbix_custom';
47 47
 
48 48
   my $date_typename = 'Date';
49 49
   my $datetime_typename = 'Datetime';
-1
t/common-sqlite-fullqualified.t
... ...
@@ -39,7 +39,6 @@ use DBIx::Custom;
39 39
   has key8 => $key8;
40 40
   has key9 => $key9;
41 41
   has key10 => $key10;
42
-  has setup_model_args => sub { [database => 'main', prefix => 1] };
43 42
   
44 43
   my $date_typename = 'Date';
45 44
   my $datetime_typename = 'Datetime';
+1
t/common-sqlite.t
... ...
@@ -39,6 +39,7 @@ use DBIx::Custom;
39 39
   has key8 => $key8;
40 40
   has key9 => $key9;
41 41
   has key10 => $key10;
42
+  has default_schema => 'main';
42 43
   
43 44
   my $date_typename = 'Date';
44 45
   my $datetime_typename = 'Datetime';
+9 -10
t/common.t
... ...
@@ -75,7 +75,6 @@ my $date_typename = $dbi->date_typename;
75 75
 my $datetime_typename = $dbi->datetime_typename;
76 76
 my $date_datatype = $dbi->date_datatype;
77 77
 my $datetime_datatype = $dbi->datetime_datatype;
78
-my $setup_model_args = $dbi->can('setup_model_args') ? $dbi->setup_model_args : [];
79 78
 
80 79
 # Variables
81 80
 my $builder;
... ...
@@ -2565,7 +2564,7 @@ eval { $dbi->execute("drop table $table2") };
2565 2564
 $dbi->execute($create_table1);
2566 2565
 $dbi->execute($create_table2);
2567 2566
 $dbi->separator('__');
2568
-$dbi->setup_model(@$setup_model_args);
2567
+$dbi->setup_model;
2569 2568
 $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2570 2569
 $dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
2571 2570
 $model = $dbi->model($table1);
... ...
@@ -2608,7 +2607,7 @@ eval { $dbi->execute("drop table $table1") };
2608 2607
 eval { $dbi->execute("drop table $table2") };
2609 2608
 $dbi->execute($create_table1);
2610 2609
 $dbi->execute($create_table2);
2611
-$dbi->setup_model(@$setup_model_args);
2610
+$dbi->setup_model;
2612 2611
 $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
2613 2612
 $dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
2614 2613
 $model = $dbi->model($table1);
... ...
@@ -3067,7 +3066,7 @@ eval { $dbi->execute("drop table $table1") };
3067 3066
 eval { $dbi->execute("drop table $table2") };
3068 3067
 $dbi->execute($create_table1);
3069 3068
 $dbi->execute($create_table2);
3070
-$dbi->setup_model(@$setup_model_args);
3069
+$dbi->setup_model;
3071 3070
 $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3072 3071
 $dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
3073 3072
 $model = $dbi->model($table1);
... ...
@@ -3103,7 +3102,7 @@ $dbi->create_model(
3103 3102
 $model2 = $dbi->create_model(
3104 3103
   table => $table2,
3105 3104
 );
3106
-$dbi->setup_model(@$setup_model_args);
3105
+$dbi->setup_model;
3107 3106
 $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3108 3107
 $dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
3109 3108
 $model = $dbi->model($table1);
... ...
@@ -3160,7 +3159,7 @@ $dbi->create_model(
3160 3159
   ],
3161 3160
   primary_key => [$key1],
3162 3161
 );
3163
-$dbi->setup_model(@$setup_model_args);
3162
+$dbi->setup_model;
3164 3163
 $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
3165 3164
 $model = $dbi->model($table1);
3166 3165
 $result = $model->select(column => $key1);
... ...
@@ -3945,7 +3944,7 @@ test 'dbi method from model';
3945 3944
 $dbi = MyDBI9->connect;
3946 3945
 eval { $dbi->execute("drop table $table1") };
3947 3946
 $dbi->execute($create_table1);
3948
-$dbi->setup_model(@$setup_model_args);
3947
+$dbi->setup_model;
3949 3948
 $model = $dbi->model($table1);
3950 3949
 eval{$model->execute("select * from $table1")};
3951 3950
 ok(!$@);
... ...
@@ -3957,7 +3956,7 @@ eval { $dbi->execute("drop table $table1") };
3957 3956
 $dbi->execute($create_table1);
3958 3957
 eval { $dbi->execute("drop table $table2") };
3959 3958
 $dbi->execute($create_table2);
3960
-$dbi->setup_model(@$setup_model_args);
3959
+$dbi->setup_model;
3961 3960
 $dbi->execute("insert into $table1 ($key1, $key2) values (1, 2)");
3962 3961
 $dbi->execute("insert into $table2 ($key1, $key3) values (1, 4)");
3963 3962
 $model = $dbi->model($table1);
... ...
@@ -4014,7 +4013,7 @@ $dbi->create_model(
4014 4013
     $key1 => {in => sub { uc $_[0] }}
4015 4014
   ]
4016 4015
 );
4017
-$dbi->setup_model(@$setup_model_args);
4016
+$dbi->setup_model;
4018 4017
 $dbi->insert({$key1 => 1, $key2 => 2}, table => $table1);
4019 4018
 $dbi->insert({$key1 => 1, $key3 => 3}, table => $table2);
4020 4019
 $model = $dbi->model($table1);
... ...
@@ -4199,7 +4198,7 @@ eval { $dbi->execute("drop table $table2") };
4199 4198
 
4200 4199
 $dbi->execute($create_table1);
4201 4200
 $dbi->execute($create_table2);
4202
-$dbi->setup_model(@$setup_model_args);
4201
+$dbi->setup_model;
4203 4202
 is_deeply([sort @{$dbi->model($table1)->columns}], [$key1, $key2]);
4204 4203
 is_deeply([sort @{$dbi->model($table2)->columns}], [$key1, $key3]);
4205 4204