Showing 5 changed files with 51 additions and 2 deletions
+1
Changes
... ...
@@ -1,4 +1,5 @@
1 1
 0.1648
2
+  add DBIx::Custom::Model foreign_key() attribute 
2 3
   add models() attribute
3 4
 0.1647
4 5
   add default_dbi_option()
+7
lib/DBIx/Custom/Guide.pod
... ...
@@ -1035,6 +1035,13 @@ If you want to get all models, you can get them by keys of C<models()>.
1035 1035
 
1036 1036
     my @models = keys %{$self->models};
1037 1037
 
1038
+You can set primary key to model.
1039
+
1040
+   $model->primary_key(['id', 'number_id']);
1041
+
1042
+Primary key is used by C<update_at()>, C<delete_at()>,
1043
+C<select_at()>.
1044
+
1038 1045
 =head2 Model Examples
1039 1046
 
1040 1047
 Model examples
+7
lib/DBIx/Custom/Guide/Ja.pod
... ...
@@ -1063,6 +1063,13 @@ L<DBIx::Custom>とL<DBI>のすべてのメソッドを呼び出すこともで
1063 1063
 
1064 1064
     my @models = keys %{$self->models};
1065 1065
 
1066
+モデルにはプライマリーキーを設定することもできます。
1067
+
1068
+   $model->primary_key(['id', 'number_id']);
1069
+
1070
+ここで設定したプライマリーキーはC<update_at()>, C<delete_at()>,
1071
+C<select_at()>で利用されます。
1072
+
1066 1073
 =head2 モデルのサンプル
1067 1074
 
1068 1075
 モデルのサンプルです。
+29 -2
lib/DBIx/Custom/Model.pm
... ...
@@ -10,7 +10,10 @@ use Carp 'croak';
10 10
 # Carp trust relationship
11 11
 push @DBIx::Custom::CARP_NOT, __PACKAGE__;
12 12
 
13
-__PACKAGE__->attr(['dbi', 'table']);
13
+__PACKAGE__->attr(
14
+    ['dbi', 'table'],
15
+    primary_key => sub { [] }
16
+);
14 17
 
15 18
 our $AUTOLOAD;
16 19
 
... ...
@@ -69,7 +72,7 @@ sub DESTROY { }
69 72
 
70 73
 =head1 NAME
71 74
 
72
-DBIx::Custom::Table - Table base class(experimental)
75
+DBIx::Custom::Model - Model (experimental)
73 76
 
74 77
 =head1 SYNOPSIS
75 78
 
... ...
@@ -77,6 +80,30 @@ use DBIx::Custom::Table;
77 80
 
78 81
 my $table = DBIx::Custom::Model->new(table => 'books');
79 82
 
83
+=head1 ATTRIBUTES
84
+
85
+=head2 C<dbi>
86
+
87
+    my $dbi = $model->dbi;
88
+    $model  = $model->dbi($dbi);
89
+
90
+L<DBIx::Custom> object.
91
+
92
+=head2 C<table>
93
+
94
+    my $table = $model->table;
95
+    $model    = $model->table('book');
96
+
97
+Table name.
98
+    
99
+=head2 C<primary_key>
100
+
101
+    my $primary_key = $model->primary_key;
102
+    $model          = $model->primary_key(['id', 'number']);
103
+
104
+Foreign key. This is used by C<update_at()>, C<delete_at()>,
105
+C<select_at()>.
106
+
80 107
 =head1 METHODS
81 108
 
82 109
 L<DBIx::Custom> inherits all methods from L<Object::Simple>,
+7
t/dbix-custom-core-sqlite.t
... ...
@@ -1371,4 +1371,11 @@ is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
1371 1371
 $model = $dbi->model('book');
1372 1372
 is_deeply($model->list->fetch_hash_all, [{name => 'a'}], 'include all model');
1373 1373
 
1374
+test 'primary_key';
1375
+use MyDBI1;
1376
+$dbi = MyDBI1->connect($NEW_ARGS->{0});
1377
+$model = $dbi->model('book');
1378
+$model->primary_key(['id', 'number']);
1379
+is_deeply($model->primary_key, ['id', 'number']);
1380
+
1374 1381