Showing 9 changed files with 283 additions and 201 deletions
+186 -184
Changes
... ...
@@ -1,260 +1,262 @@
1
+0.1649
2
+    - DBIx::Custom::Model select() think about relation attirbute
1 3
 0.1648
2
-  add experimental DBIx::Custom::Model relation() attribute
3
-  add experimental update_at(), delete_at(), select_at()
4
-  add experimental setup_model()
5
-  add experimental DBIx::Custom::Model columns attirbute
6
-  add experimental DBIx::Custom::Model foreign_key() attribute 
7
-  add experimental models() attribute
4
+    - add experimental DBIx::Custom::Model relation() attribute
5
+    - add experimental update_at(), delete_at(), select_at()
6
+    - add experimental setup_model()
7
+    - add experimental DBIx::Custom::Model columns attirbute
8
+    - add experimental DBIx::Custom::Model foreign_key() attribute 
9
+    - add experimental models() attribute
8 10
 0.1647
9
-  add default_dbi_option()
11
+    - add default_dbi_option()
10 12
 0.1646
11
-  add feture. all model class in namespace is included by include_model
12
-  rename experimental include_table to include_model
13
-  rename experimental table to model
14
-  rename experimental DBIx::Custom::Table to DBIx::Custom::Model
15
-  remame experimental DBIx::Custom::Table::name() to DBIx::Custom::Model::table();
13
+    - add feture. all model class in namespace is included by include_model
14
+    - rename experimental include_table to include_model
15
+    - rename experimental table to model
16
+    - rename experimental DBIx::Custom::Table to DBIx::Custom::Model
17
+    - remame experimental DBIx::Custom::Table::name() to DBIx::Custom::Model::table();
16 18
 0.1645
17
-  removed experimental base_table() for class expandability.
18
-  experimental table() can't set table object any more.
19
-  added experimental include_table().
19
+    - removed experimental base_table() for class expandability.
20
+    - experimental table() can't set table object any more.
21
+    - added experimental include_table().
20 22
 0.1644
21
-  update pod
23
+    - update pod
22 24
 0.1643
23
-  add experimental selection option to select()
24
-  add experimental table tag
25
-  fix bug : filter can't overwirite undef value.
26
-  add experimental feature to apply_filter(). you can apply end filter.
27
-  add experimental feature to apply_filter(). TABLE__COLUMN is filterded now.
25
+    - add experimental selection option to select()
26
+    - add experimental table tag
27
+    - fix bug : filter can't overwirite undef value.
28
+    - add experimental feature to apply_filter(). you can apply end filter.
29
+    - add experimental feature to apply_filter(). TABLE__COLUMN is filterded now.
28 30
 0.1642
29
-  removed experimental DBIx::Custom::Table base() method
30
-  table created by tabled method can call base_$method correponding to base_table's one
31
+    - removed experimental DBIx::Custom::Table base() method
32
+    - table created by tabled method can call base_$method correponding to base_table's one
31 33
 0.1641
32
-  select() where can't receive array reference to prevend SQL injection easily(not backward compatible. sorry. use where() instead)
33
-  added experimental safety_column_name attribute
34
-  fix SQL injection security hole about column name
34
+    - select() where can't receive array reference to prevend SQL injection easily(not backward compatible. sorry. use where() instead)
35
+    - added experimental safety_column_name attribute
36
+    - fix SQL injection security hole about column name
35 37
 0.1640
36
-  autoload DBI method
37
-  removed experimental expand
38
+    - autoload DBI method
39
+    - removed experimental expand
38 40
 0.1639
39
-  improved delete() and update() where option. you can use DBIx::Custom::Where object
40
-  added experimental not_exists()
41
+    - improved delete() and update() where option. you can use DBIx::Custom::Where object
42
+    - added experimental not_exists()
41 43
 0.1638
42
-  table object call dbi object method if not found method.
43
-  added experimental base_table attribute and removed experimental table_class attribute
44
-  renamed helper to method.
45
-  added experimental DBIx::Custom::Result::stash()
46
-  renamed experimental DBIx::Custom::Table helper to method
44
+    - table object call dbi object method if not found method.
45
+    - added experimental base_table attribute and removed experimental table_class attribute
46
+    - renamed helper to method.
47
+    - added experimental DBIx::Custom::Result::stash()
48
+    - renamed experimental DBIx::Custom::Table helper to method
47 49
 0.1637
48
-  renamed dbi_options to dbi_option. dbi_options is available, but deprecated.
49
-  renamed DBIx::Custom::TagProcessor to DBIx::Custom::Tag, and function names is cleanuped.
50
-  renamed register_tag_processor to register_tag. register_tag_processor is available, but deprecated.
51
-  renamed tag_processors to tags. tag_prosessors is available, but deprecated.
52
-  improved error message
53
-  build all clause if param is undefined.
54
-  each_column callback receive self as first argument.
55
-  removed experimental txn_scope
50
+    - renamed dbi_options to dbi_option. dbi_options is available, but deprecated.
51
+    - renamed DBIx::Custom::TagProcessor to DBIx::Custom::Tag, and function names is cleanuped.
52
+    - renamed register_tag_processor to register_tag. register_tag_processor is available, but deprecated.
53
+    - renamed tag_processors to tags. tag_prosessors is available, but deprecated.
54
+    - improved error message
55
+    - build all clause if param is undefined.
56
+    - each_column callback receive self as first argument.
57
+    - removed experimental txn_scope
56 58
 0.1636
57
-  added tests and cleanup
59
+    - added tests and cleanup
58 60
 0.1635
59
-  renamed iterate_all_columns to each_column
61
+    - renamed iterate_all_columns to each_column
60 62
 0.1634
61
-  became more useful where method
62
-  changed DBIx::Custom::Where greatly
63
+    - became more useful where method
64
+    - changed DBIx::Custom::Where greatly
63 65
 0.1633
64
-  fixed test
66
+    - fixed test
65 67
 0.1632
66
-  added experimental where method
67
-  added experimental DBIx::Custom::Where.
68
-  removed DBIx::Custom::Or
68
+    - added experimental where method
69
+    - added experimental DBIx::Custom::Where.
70
+    - removed DBIx::Custom::Or
69 71
 0.1631
70
-  added experimental DBIx::Custom::Result end_filter method
71
-  experimental extended select method's where option
72
-  fix select method empty where failed bug
73
-  added experimental suger method query option
74
-  added experimental or method
72
+    - added experimental DBIx::Custom::Result end_filter method
73
+    - experimental extended select method's where option
74
+    - fix select method empty where failed bug
75
+    - added experimental suger method query option
76
+    - added experimental or method
75 77
 0.1630
76
-  fix test bug
78
+    - fix test bug
77 79
 0.1629
78
-  renamed auto_filter to apply_filter
79
-  changed apply_filter method arguments
80
-  deprecated cache_method
80
+    - renamed auto_filter to apply_filter
81
+    - changed apply_filter method arguments
82
+    - deprecated cache_method
81 83
 0.1628
82
-  remove DBIx::Custom::Model
83
-  move table method and table_class attribute to DBIx::Custom
84
-  added examples
85
-  fixed connect method bug
84
+    - remove DBIx::Custom::Model
85
+    - move table method and table_class attribute to DBIx::Custom
86
+    - added examples
87
+    - fixed connect method bug
86 88
 0.1627
87
-  added insert, update, update_all, delete, delete_all, select method to DBIx::Custom::Table
88
-  added experimental txn_scope
89
+    - added insert, update, update_all, delete, delete_all, select method to DBIx::Custom::Table
90
+    - added experimental txn_scope
89 91
 0.1626
90
-  simplified DBIx::Custom::Model and DBIx::Custom::Table
92
+    - simplified DBIx::Custom::Model and DBIx::Custom::Table
91 93
 0.1625
92
-  added experimental DBIx::Custom::Model and DBIx::Custom::Table
94
+    - added experimental DBIx::Custom::Model and DBIx::Custom::Table
93 95
 0.1624
94
-  added experimental iterate_all_columns method.
96
+    - added experimental iterate_all_columns method.
95 97
 0.1623
96
-  added experimental auto_filter method
97
-  deprecated default_bind_filter and default_fetch_filter because these are global effect.
98
-  changed defautl_bind_filter and default_fetch_filter attributes to methods.
99
-  changed DBIx::Custom::Result default_filter attribute to method
100
-  changed DBIx::Custom::Result filter attribute to method.
101
-  filter_check is always done for usability
98
+    - added experimental auto_filter method
99
+    - deprecated default_bind_filter and default_fetch_filter because these are global effect.
100
+    - changed defautl_bind_filter and default_fetch_filter attributes to methods.
101
+    - changed DBIx::Custom::Result default_filter attribute to method
102
+    - changed DBIx::Custom::Result filter attribute to method.
103
+    - filter_check is always done for usability
102 104
 0.1622
103
-  deprecated DBIx::Custom::SQLite and DBIx::Custom::MySQL
104
-  added dbi_options attribute
105
-  checked attributes passed to connect method
105
+    - deprecated DBIx::Custom::SQLite and DBIx::Custom::MySQL
106
+    - added dbi_options attribute
107
+    - checked attributes passed to connect method
106 108
 0.1621
107
-  cleanup (removed undocumented features)
109
+    - cleanup (removed undocumented features)
108 110
 0.1620
109
-  updated document
111
+    - updated document
110 112
 0.1619
111
-  updated document
112
-  added experimental expand method
113
+    - updated document
114
+    - added experimental expand method
113 115
 0.1618
114
-  added helper method
115
-  added begin_work, commit, and rollback method
116
+    - added helper method
117
+    - added begin_work, commit, and rollback method
116 118
 0.1617
117
-  L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature.
119
+    - L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature.
118 120
 0.1616
119
-  removed experimental register_method(), and methods attribute, because it is too magical
121
+    - removed experimental register_method(), and methods attribute, because it is too magical
120 122
 0.1615
121
-  fixed DBIx::Custom::QueryBuilder build_query() bug
122
-  required Perl 5.008001 to use @CARP_NOT 
123
+    - fixed DBIx::Custom::QueryBuilder build_query() bug
124
+    - required Perl 5.008001 to use @CARP_NOT 
123 125
 0.1614
124
-  removed DBIx::Custom::Query start_tag and end tag attributes
125
-  enable escaping '{' and '}' in the source of SQL
126
-  fixed Carp Carp trust relationship
126
+    - removed DBIx::Custom::Query start_tag and end tag attributes
127
+    - enable escaping '{' and '}' in the source of SQL
128
+    - fixed Carp Carp trust relationship
127 129
 0.1613
128
-  added experimental register_method() method
129
-  added experimental methods attribute
130
+    - added experimental register_method() method
131
+    - added experimental methods attribute
130 132
 0.1612
131
-  added tests
132
-  updated document
133
-  removed DBIx::Custom::SQLite last_insert_rawid() mehtod(not backword compatible)
134
-  removed DBIx::Custom::MySQL last_insert_id() method(not backword compatible)
133
+    - added tests
134
+    - updated document
135
+    - removed DBIx::Custom::SQLite last_insert_rawid() mehtod(not backword compatible)
136
+    - removed DBIx::Custom::MySQL last_insert_id() method(not backword compatible)
135 137
 0.1611
136
-  renamed update tag to update_param
137
-  renamed insert tag to insert_param
138
-  renamed sql_builder to query_builder
138
+    - renamed update tag to update_param
139
+    - renamed insert tag to insert_param
140
+    - renamed sql_builder to query_builder
139 141
 0.1610
140
-  added filter_check attribute.
142
+    - added filter_check attribute.
141 143
 0.1609
142
-  updated document.
144
+    - updated document.
143 145
 0.1608
144
-  update document
145
-  renamed DBIx::Custom::QueryBuilder::TagProcessors functions(not backword compatible)
146
+    - update document
147
+    - renamed DBIx::Custom::QueryBuilder::TagProcessors functions(not backword compatible)
146 148
 0.1607
147
-  where argument of select() method can specify array(string, paramters)
148
-  renamed build_query() to create_query()(not backword compatible)
149
+    - where argument of select() method can specify array(string, paramters)
150
+    - renamed build_query() to create_query()(not backword compatible)
149 151
 0.1606
150
-  fix testing bug
152
+    - fix testing bug
151 153
 0.1605
152
-  remove DBIx::Custom::QueryBuilder::tag_syntax()  (not backword compatible)
153
-  renamed DBIx::Custom::TagProcessor to DBIx::Custom::TagProcessors (not backword compatible)
154
-  changed arguments of tag processor(not backword compatible)
155
-  renamed DBIx::Custom::QueryBuilder::TagProcessors functions(not backword compatible)
154
+    - remove DBIx::Custom::QueryBuilder::tag_syntax()  (not backword compatible)
155
+    - renamed DBIx::Custom::TagProcessor to DBIx::Custom::TagProcessors (not backword compatible)
156
+    - changed arguments of tag processor(not backword compatible)
157
+    - renamed DBIx::Custom::QueryBuilder::TagProcessors functions(not backword compatible)
156 158
 0.1604
157
-  changed argument of tag processor(not backword compatible)
158
-  renamed default_query_filter to default_bind_filter(not backword compatible)
159
-  renamed DBIx::Custom::SQLTemplate to DBIx::Custom::SQLBuilder(not backword compatible)
160
-  renamed create_query to build_query(not backword compatible)
161
-  renamed sql_template to sql_builder(not backword compatible)
162
-  removed DESTROY method(not backword compatible)
163
-  removed disconnect method(not backword compatible)
164
-  fixed DBIx::Custom::MySQL connect_memory
159
+    - changed argument of tag processor(not backword compatible)
160
+    - renamed default_query_filter to default_bind_filter(not backword compatible)
161
+    - renamed DBIx::Custom::SQLTemplate to DBIx::Custom::SQLBuilder(not backword compatible)
162
+    - renamed create_query to build_query(not backword compatible)
163
+    - renamed sql_template to sql_builder(not backword compatible)
164
+    - removed DESTROY method(not backword compatible)
165
+    - removed disconnect method(not backword compatible)
166
+    - fixed DBIx::Custom::MySQL connect_memory
165 167
 0.1603
166
-  removed DBIx::Custom commit method (not backword compatible)
167
-  removed DBIx::Custom rollback method (not backword compatible)
168
-  removed DBIx::Custom auto_commit method (not backword compatible)
168
+    - removed DBIx::Custom commit method (not backword compatible)
169
+    - removed DBIx::Custom rollback method (not backword compatible)
170
+    - removed DBIx::Custom auto_commit method (not backword compatible)
169 171
 0.1602
170
-  added cache_method attribute
172
+    - added cache_method attribute
171 173
 0.1601
172
-  added cache attribute
173
-  select, insert, update, update_all, delete, delete_all, execute only receive hash argument(not backword compatible)
174
+    - added cache attribute
175
+    - select, insert, update, update_all, delete, delete_all, execute only receive hash argument(not backword compatible)
174 176
 0.1503
175
-  removed reconnect method
176
-  removed connected method
177
-  removed reconnect_memroy method
178
-  renamed fetch_single to fetch_first
179
-  renamed fetch_hash_single to fetch_hash_first
180
-  updated document
177
+    - removed reconnect method
178
+    - removed connected method
179
+    - removed reconnect_memroy method
180
+    - renamed fetch_single to fetch_first
181
+    - renamed fetch_hash_single to fetch_hash_first
182
+    - updated document
181 183
 0.1502
182
-  added commit method
183
-  added rollback method
184
-  changed select argument, added relation option
185
-  moved host attribute to DBIx::Custom::MySQL
186
-  moved port attribute to DBIx::Custom::MySQL
187
-  moved database attribute to DBIx::Custom::MySQL and DBIx::Custom::SQLite
184
+    - added commit method
185
+    - added rollback method
186
+    - changed select argument, added relation option
187
+    - moved host attribute to DBIx::Custom::MySQL
188
+    - moved port attribute to DBIx::Custom::MySQL
189
+    - moved database attribute to DBIx::Custom::MySQL and DBIx::Custom::SQLite
188 190
 0.1501
189
-  removed register_format()
190
-  removed formats()
191
-  removed run_transaction()
192
-  removed create_table()
193
-  removed drop_table()
194
-  changed select() arguments
195
-  changed insert() arguments
196
-  changed update() arguments
197
-  changed update_all() arguments
198
-  changed delete() arguments
199
-  changed delete_all() arguments
200
-  changed execute() arguments
191
+    - removed register_format()
192
+    - removed formats()
193
+    - removed run_transaction()
194
+    - removed create_table()
195
+    - removed drop_table()
196
+    - changed select() arguments
197
+    - changed insert() arguments
198
+    - changed update() arguments
199
+    - changed update_all() arguments
200
+    - changed delete() arguments
201
+    - changed delete_all() arguments
202
+    - changed execute() arguments
201 203
 0.1402
202
-  remove finish(), error()
203
-  can receive code ref to filter()
204
-  renamed resist to register
204
+    - remove finish(), error()
205
+    - can receive code ref to filter()
206
+    - renamed resist to register
205 207
 0.1401
206
-  renamed fetch_rows to fetch_multi
207
-  renamed fetch_hash_rows to fetch_hash_multi
208
+    - renamed fetch_rows to fetch_multi
209
+    - renamed fetch_hash_rows to fetch_hash_multi
208 210
 0.1301
209
-  Changed many(not backword compatible)
211
+    - Changed many(not backword compatible)
210 212
 0.1201
211
-  Changed many(not backword compatible)
213
+    - Changed many(not backword compatible)
212 214
 0.1101
213
-  rename DBIx::Custom::SQLite last_insert_id to last_insert_rowid
215
+    - rename DBIx::Custom::SQLite last_insert_id to last_insert_rowid
214 216
 0.1001
215
-  remove run_transaction().
216
-  add transaction() and DBIx::Custom::Transaction
217
-  rename fetch_first to fetch_single
218
-  rename fetch_hash_first to fetch_hash_single
217
+    - remove run_transaction().
218
+    - add transaction() and DBIx::Custom::Transaction
219
+    - rename fetch_first to fetch_single
220
+    - rename fetch_hash_first to fetch_hash_single
219 221
 0.0906
220
-  fix some bug
222
+    - fix some bug
221 223
 0.0905
222
-  catch up with Object::Simple update
224
+    - catch up with Object::Simple update
223 225
 0.0904
224
-  cleanup
226
+    - cleanup
225 227
 0.0903
226
-  catch up with Object::Simple update
228
+    - catch up with Object::Simple update
227 229
 0.0902
228
-  cleanup
230
+    - cleanup
229 231
 0.0901
230
-  DBIx::Basic filter 'encode_utf8' utf8::upgrade process is deleted
232
+    - DBIx::Basic filter 'encode_utf8' utf8::upgrade process is deleted
231 233
 0.0801
232
-  add 'create_table', 'drop_table' methods
234
+    - add 'create_table', 'drop_table' methods
233 235
 0.0701
234
-  rename sql_template to sql_tmpl (not backword compatible)
235
-  rename dbi_options to options (not backword compatible)
236
+    - rename sql_template to sql_tmpl (not backword compatible)
237
+    - rename dbi_options to options (not backword compatible)
236 238
 0.0605
237
-  fix encode_utf8 filter
239
+    - fix encode_utf8 filter
238 240
 0.0604
239
-  fix timeformat tests
241
+    - fix timeformat tests
240 242
 0.0603
241
-  fix cache system bug
243
+    - fix cache system bug
242 244
 0.0602
243
-  update document
245
+    - update document
244 246
 0.0601
245
-  bind_filter argument is changed to ($value, $key, $dbi, $infos) (not backword compatible)
246
-  fetch_filter argument is changed to ($value, $key, $dbi, $infos) (not backword compatible)
247
-  run_transaction argument is changed to ($dbi)
247
+    - bind_filter argument is changed to ($value, $key, $dbi, $infos) (not backword compatible)
248
+    - fetch_filter argument is changed to ($value, $key, $dbi, $infos) (not backword compatible)
249
+    - run_transaction argument is changed to ($dbi)
248 250
 0.0502
249
-  update document
251
+    - update document
250 252
 0.0501
251
-  packaging DBIx::Custom::Result DBIx::Custom::Query DBIx::Custom::MySQL DBIx::Custom::SQLite DBIx::Custom::SQL::Template 
253
+    - packaging DBIx::Custom::Result DBIx::Custom::Query DBIx::Custom::MySQL DBIx::Custom::SQLite DBIx::Custom::SQL::Template 
252 254
 0.0401
253
-  catch up with DBIx::Custom::Result version up
255
+    - catch up with DBIx::Custom::Result version up
254 256
 0.0301
255
-  exchange filter argument 'key', 'value' (not backword compatible)
257
+    - exchange filter argument 'key', 'value' (not backword compatible)
256 258
 0.0201
257
-  rename tranzaction to transaction
258
-  add filter_off
259
+    - rename tranzaction to transaction
260
+    - add filter_off
259 261
 0.0101
260
-  First release
262
+    - First release
+12 -8
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1648';
3
+our $VERSION = '0.1649';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -552,12 +552,12 @@ sub select {
552 552
     my $columns   = $args{column} || [];
553 553
     my $selection = $args{selection} || '';
554 554
     my $where     = $args{where} || {};
555
-    my $relation  = $args{relation};
555
+    my $relation  = $args{relation} || {};
556 556
     my $append    = $args{append};
557 557
     my $filter    = $args{filter};
558 558
 
559
-    # Relation table
560
-    if (!$selection && $relation) {
559
+    # Relation
560
+    if (!$selection && keys %$relation) {
561 561
         foreach my $rcolumn (keys %$relation) {
562 562
             my $table1 = (split (/\./, $rcolumn))[0];
563 563
             my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
... ...
@@ -568,8 +568,8 @@ sub select {
568 568
                 $table1_exists = 1 if $table eq $table1;
569 569
                 $table2_exists = 1 if $table eq $table2;
570 570
             }
571
-            push @$tables, $table1 unless $table1_exists;
572
-            push @$tables, $table2 unless $table2_exists;
571
+            unshift @$tables, $table1 unless $table1_exists;
572
+            unshift @$tables, $table2 unless $table2_exists;
573 573
         }
574 574
     }
575 575
     
... ...
@@ -624,7 +624,7 @@ sub select {
624 624
     push @sql, $swhere;
625 625
     
626 626
     # Relation
627
-    if (!$selection && $relation) {
627
+    if (!$selection && keys %$relation) {
628 628
         push @sql, $swhere eq '' ? 'where' : 'and';
629 629
         foreach my $rcolumn (keys %$relation) {
630 630
             my $table1 = (split (/\./, $rcolumn))[0];
... ...
@@ -671,6 +671,10 @@ sub select_at {
671 671
     my $primary_keys = delete $args{primary_key};
672 672
     $primary_keys = [$primary_keys] unless ref $primary_keys;
673 673
     
674
+    # Table
675
+    croak qq{"table" option must be specified} unless $args{table};
676
+    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
677
+    
674 678
     # Where clause
675 679
     my $where = {};
676 680
     if (exists $args{where}) {
... ...
@@ -678,7 +682,7 @@ sub select_at {
678 682
         $where_columns = [$where_columns] unless ref $where_columns;
679 683
         
680 684
         for(my $i = 0; $i < @$primary_keys; $i ++) {
681
-           $where->{$primary_keys->[$i]} = $where_columns->[$i];
685
+           $where->{$table . '.' . $primary_keys->[$i]} = $where_columns->[$i];
682 686
         }
683 687
     }
684 688
     elsif (exists $args{param}) {
+1 -1
lib/DBIx/Custom/Guide.pod
... ...
@@ -313,7 +313,7 @@ Following SQL is executed.
313 313
 Next example.
314 314
 
315 315
     my $result = $dbi->select(
316
-        table    => ['book', 'rental'],
316
+        table    => 'book',
317 317
         where    => {'book.name' => 'Perl'},
318 318
         relation => {'book.id' => 'rental.book_id'}
319 319
     );
+1 -1
lib/DBIx/Custom/Guide/Ja.pod
... ...
@@ -317,7 +317,7 @@ C<column>は列名、C<where>は条件です。
317 317
 次のサンプルです。
318 318
 
319 319
     my $result = $dbi->select(
320
-        table    => ['book', 'rental'],
320
+        table    => 'book',
321 321
         where    => {book.name => 'Perl'},
322 322
         relation => {'book.id' => 'rental.book_id'}
323 323
     );
+34 -7
lib/DBIx/Custom/Model.pm
... ...
@@ -51,12 +51,39 @@ sub method {
51 51
     return $self;
52 52
 }
53 53
 
54
-sub insert     { my $self = shift; $self->dbi->insert(table => $self->table, @_) }
55
-sub update     { my $self = shift; $self->dbi->update(table => $self->table, @_) }
56
-sub update_all { my $self = shift; $self->dbi->update_all(table => $self->table, @_) }
57
-sub delete     { my $self = shift; $self->dbi->delete(table => $self->table, @_) }
58
-sub delete_all { my $self = shift; $self->dbi->delete_all(table => $self->table, @_) }
59
-sub select     { my $self = shift; $self->dbi->select(table => $self->table, @_) }
54
+sub insert {
55
+    my $self = shift;
56
+    $self->dbi->insert(table => $self->table, @_);
57
+}
58
+
59
+sub update {
60
+    my $self = shift;
61
+    $self->dbi->update(table => $self->table, @_)
62
+}
63
+
64
+sub update_all {
65
+    my $self = shift;
66
+    $self->dbi->update_all(table => $self->table, @_);
67
+}
68
+
69
+sub delete {
70
+    my $self = shift;
71
+    $self->dbi->delete(table => $self->table, @_);
72
+}
73
+
74
+sub delete_all {
75
+    my $self = shift;
76
+    $self->dbi->delete_all(table => $self->table, @_);
77
+}
78
+
79
+sub select {
80
+    my $self = shift;
81
+    $self->dbi->select(
82
+        table => $self->table,
83
+        relation => $self->relation,
84
+        @_
85
+    );
86
+}
60 87
 
61 88
 sub update_at {
62 89
     my $self = shift;
... ...
@@ -84,9 +111,9 @@ sub select_at {
84 111
     return $self->dbi->select_at(
85 112
         table => $self->table,
86 113
         primary_key => $self->primary_key,
114
+        relation => $self->relation,
87 115
         @_
88 116
     );
89
-    return $self;
90 117
 }
91 118
 
92 119
 sub DESTROY { }
+25
t/dbix-custom-core-sqlite.t
... ...
@@ -1558,3 +1558,28 @@ $row = $result->fetch_hash_first;
1558 1558
 is($row->{key1}, 1);
1559 1559
 is($row->{key2}, 2);
1560 1560
 is($row->{key3}, 3);
1561
+
1562
+
1563
+test 'model select relation';
1564
+{
1565
+    package MyDBI7;
1566
+    
1567
+    use base 'DBIx::Custom';
1568
+    
1569
+    sub connect {
1570
+        my $self = shift->SUPER::connect(@_);
1571
+        
1572
+        $self->include_model('MyModel6');
1573
+        
1574
+        return $self;
1575
+    }
1576
+}
1577
+$dbi = MyDBI7->connect($NEW_ARGS->{0});
1578
+$dbi->execute($CREATE_TABLE->{0});
1579
+$dbi->execute($CREATE_TABLE->{2});
1580
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1581
+$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
1582
+$result = $dbi->model('table1')->select(column => ['key3'], where => {'table1.key1' => 1});
1583
+is($result->fetch_hash_first->{key3}, 3);
1584
+$result = $dbi->model('table1')->select_at(column => ['key3'], where => [1]);
1585
+is($result->fetch_hash_first->{key3}, 3);
+5
t/dbix-custom-core-sqlite/MyModel6.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel6;
2
+
3
+use base 'DBIx::Custom::Model';
4
+
5
+1;
+14
t/dbix-custom-core-sqlite/MyModel6/table1.pm
... ...
@@ -0,0 +1,14 @@
1
+package MyModel6::table1;
2
+
3
+use base 'MyModel6';
4
+
5
+__PACKAGE__->attr(
6
+    relation => sub {
7
+        {
8
+            'table1.key1' => 'table2.key1'
9
+        }
10
+    },
11
+    primary_key => sub { ['key1'] }
12
+);
13
+
14
+1;
+5
t/dbix-custom-core-sqlite/MyModel6/table2.pm
... ...
@@ -0,0 +1,5 @@
1
+package MyModel6::table2;
2
+
3
+use base 'MyModel6';
4
+
5
+1;