Bug 13713: Remove useless constraints previously added
[koha.git] / Koha / Schema / Result / Item.pm
1 use utf8;
2 package Koha::Schema::Result::Item;
3
4 # Created by DBIx::Class::Schema::Loader
5 # DO NOT MODIFY THE FIRST PART OF THIS FILE
6
7 =head1 NAME
8
9 Koha::Schema::Result::Item
10
11 =cut
12
13 use strict;
14 use warnings;
15
16 use base 'DBIx::Class::Core';
17
18 =head1 TABLE: C<items>
19
20 =cut
21
22 __PACKAGE__->table("items");
23
24 =head1 ACCESSORS
25
26 =head2 itemnumber
27
28   data_type: 'integer'
29   is_auto_increment: 1
30   is_nullable: 0
31
32 =head2 biblionumber
33
34   data_type: 'integer'
35   default_value: 0
36   is_nullable: 0
37
38 =head2 biblioitemnumber
39
40   data_type: 'integer'
41   default_value: 0
42   is_foreign_key: 1
43   is_nullable: 0
44
45 =head2 barcode
46
47   data_type: 'varchar'
48   is_nullable: 1
49   size: 20
50
51 =head2 dateaccessioned
52
53   data_type: 'date'
54   datetime_undef_if_invalid: 1
55   is_nullable: 1
56
57 =head2 booksellerid
58
59   data_type: 'mediumtext'
60   is_nullable: 1
61
62 =head2 homebranch
63
64   data_type: 'varchar'
65   is_foreign_key: 1
66   is_nullable: 1
67   size: 10
68
69 =head2 price
70
71   data_type: 'decimal'
72   is_nullable: 1
73   size: [8,2]
74
75 =head2 replacementprice
76
77   data_type: 'decimal'
78   is_nullable: 1
79   size: [8,2]
80
81 =head2 replacementpricedate
82
83   data_type: 'date'
84   datetime_undef_if_invalid: 1
85   is_nullable: 1
86
87 =head2 datelastborrowed
88
89   data_type: 'date'
90   datetime_undef_if_invalid: 1
91   is_nullable: 1
92
93 =head2 datelastseen
94
95   data_type: 'date'
96   datetime_undef_if_invalid: 1
97   is_nullable: 1
98
99 =head2 stack
100
101   data_type: 'tinyint'
102   is_nullable: 1
103
104 =head2 notforloan
105
106   data_type: 'tinyint'
107   default_value: 0
108   is_nullable: 0
109
110 =head2 damaged
111
112   data_type: 'tinyint'
113   default_value: 0
114   is_nullable: 0
115
116 =head2 itemlost
117
118   data_type: 'tinyint'
119   default_value: 0
120   is_nullable: 0
121
122 =head2 itemlost_on
123
124   data_type: 'datetime'
125   datetime_undef_if_invalid: 1
126   is_nullable: 1
127
128 =head2 withdrawn
129
130   data_type: 'tinyint'
131   default_value: 0
132   is_nullable: 0
133
134 =head2 withdrawn_on
135
136   data_type: 'datetime'
137   datetime_undef_if_invalid: 1
138   is_nullable: 1
139
140 =head2 itemcallnumber
141
142   data_type: 'varchar'
143   is_nullable: 1
144   size: 255
145
146 =head2 coded_location_qualifier
147
148   data_type: 'varchar'
149   is_nullable: 1
150   size: 10
151
152 =head2 issues
153
154   data_type: 'smallint'
155   is_nullable: 1
156
157 =head2 renewals
158
159   data_type: 'smallint'
160   is_nullable: 1
161
162 =head2 reserves
163
164   data_type: 'smallint'
165   is_nullable: 1
166
167 =head2 restricted
168
169   data_type: 'tinyint'
170   is_nullable: 1
171
172 =head2 itemnotes
173
174   data_type: 'mediumtext'
175   is_nullable: 1
176
177 =head2 holdingbranch
178
179   data_type: 'varchar'
180   is_foreign_key: 1
181   is_nullable: 1
182   size: 10
183
184 =head2 paidfor
185
186   data_type: 'mediumtext'
187   is_nullable: 1
188
189 =head2 timestamp
190
191   data_type: 'timestamp'
192   datetime_undef_if_invalid: 1
193   default_value: current_timestamp
194   is_nullable: 0
195
196 =head2 location
197
198   data_type: 'varchar'
199   is_nullable: 1
200   size: 80
201
202 =head2 permanent_location
203
204   data_type: 'varchar'
205   is_nullable: 1
206   size: 80
207
208 =head2 onloan
209
210   data_type: 'date'
211   datetime_undef_if_invalid: 1
212   is_nullable: 1
213
214 =head2 cn_source
215
216   data_type: 'varchar'
217   is_nullable: 1
218   size: 10
219
220 =head2 cn_sort
221
222   data_type: 'varchar'
223   is_nullable: 1
224   size: 255
225
226 =head2 ccode
227
228   data_type: 'varchar'
229   is_nullable: 1
230   size: 10
231
232 =head2 materials
233
234   data_type: 'text'
235   is_nullable: 1
236
237 =head2 uri
238
239   data_type: 'varchar'
240   is_nullable: 1
241   size: 255
242
243 =head2 itype
244
245   data_type: 'varchar'
246   is_nullable: 1
247   size: 10
248
249 =head2 more_subfields_xml
250
251   data_type: 'longtext'
252   is_nullable: 1
253
254 =head2 enumchron
255
256   data_type: 'text'
257   is_nullable: 1
258
259 =head2 copynumber
260
261   data_type: 'varchar'
262   is_nullable: 1
263   size: 32
264
265 =head2 stocknumber
266
267   data_type: 'varchar'
268   is_nullable: 1
269   size: 32
270
271 =cut
272
273 __PACKAGE__->add_columns(
274   "itemnumber",
275   { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
276   "biblionumber",
277   { data_type => "integer", default_value => 0, is_nullable => 0 },
278   "biblioitemnumber",
279   {
280     data_type      => "integer",
281     default_value  => 0,
282     is_foreign_key => 1,
283     is_nullable    => 0,
284   },
285   "barcode",
286   { data_type => "varchar", is_nullable => 1, size => 20 },
287   "dateaccessioned",
288   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
289   "booksellerid",
290   { data_type => "mediumtext", is_nullable => 1 },
291   "homebranch",
292   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
293   "price",
294   { data_type => "decimal", is_nullable => 1, size => [8, 2] },
295   "replacementprice",
296   { data_type => "decimal", is_nullable => 1, size => [8, 2] },
297   "replacementpricedate",
298   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
299   "datelastborrowed",
300   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
301   "datelastseen",
302   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
303   "stack",
304   { data_type => "tinyint", is_nullable => 1 },
305   "notforloan",
306   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
307   "damaged",
308   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
309   "itemlost",
310   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
311   "itemlost_on",
312   {
313     data_type => "datetime",
314     datetime_undef_if_invalid => 1,
315     is_nullable => 1,
316   },
317   "withdrawn",
318   { data_type => "tinyint", default_value => 0, is_nullable => 0 },
319   "withdrawn_on",
320   {
321     data_type => "datetime",
322     datetime_undef_if_invalid => 1,
323     is_nullable => 1,
324   },
325   "itemcallnumber",
326   { data_type => "varchar", is_nullable => 1, size => 255 },
327   "coded_location_qualifier",
328   { data_type => "varchar", is_nullable => 1, size => 10 },
329   "issues",
330   { data_type => "smallint", is_nullable => 1 },
331   "renewals",
332   { data_type => "smallint", is_nullable => 1 },
333   "reserves",
334   { data_type => "smallint", is_nullable => 1 },
335   "restricted",
336   { data_type => "tinyint", is_nullable => 1 },
337   "itemnotes",
338   { data_type => "mediumtext", is_nullable => 1 },
339   "holdingbranch",
340   { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
341   "paidfor",
342   { data_type => "mediumtext", is_nullable => 1 },
343   "timestamp",
344   {
345     data_type => "timestamp",
346     datetime_undef_if_invalid => 1,
347     default_value => \"current_timestamp",
348     is_nullable => 0,
349   },
350   "location",
351   { data_type => "varchar", is_nullable => 1, size => 80 },
352   "permanent_location",
353   { data_type => "varchar", is_nullable => 1, size => 80 },
354   "onloan",
355   { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
356   "cn_source",
357   { data_type => "varchar", is_nullable => 1, size => 10 },
358   "cn_sort",
359   { data_type => "varchar", is_nullable => 1, size => 255 },
360   "ccode",
361   { data_type => "varchar", is_nullable => 1, size => 10 },
362   "materials",
363   { data_type => "text", is_nullable => 1 },
364   "uri",
365   { data_type => "varchar", is_nullable => 1, size => 255 },
366   "itype",
367   { data_type => "varchar", is_nullable => 1, size => 10 },
368   "more_subfields_xml",
369   { data_type => "longtext", is_nullable => 1 },
370   "enumchron",
371   { data_type => "text", is_nullable => 1 },
372   "copynumber",
373   { data_type => "varchar", is_nullable => 1, size => 32 },
374   "stocknumber",
375   { data_type => "varchar", is_nullable => 1, size => 32 },
376 );
377
378 =head1 PRIMARY KEY
379
380 =over 4
381
382 =item * L</itemnumber>
383
384 =back
385
386 =cut
387
388 __PACKAGE__->set_primary_key("itemnumber");
389
390 =head1 UNIQUE CONSTRAINTS
391
392 =head2 C<itembarcodeidx>
393
394 =over 4
395
396 =item * L</barcode>
397
398 =back
399
400 =cut
401
402 __PACKAGE__->add_unique_constraint("itembarcodeidx", ["barcode"]);
403
404 =head1 RELATIONS
405
406 =head2 accountlines
407
408 Type: has_many
409
410 Related object: L<Koha::Schema::Result::Accountline>
411
412 =cut
413
414 __PACKAGE__->has_many(
415   "accountlines",
416   "Koha::Schema::Result::Accountline",
417   { "foreign.itemnumber" => "self.itemnumber" },
418   { cascade_copy => 0, cascade_delete => 0 },
419 );
420
421 =head2 biblioitemnumber
422
423 Type: belongs_to
424
425 Related object: L<Koha::Schema::Result::Biblioitem>
426
427 =cut
428
429 __PACKAGE__->belongs_to(
430   "biblioitemnumber",
431   "Koha::Schema::Result::Biblioitem",
432   { biblioitemnumber => "biblioitemnumber" },
433   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
434 );
435
436 =head2 branchtransfers
437
438 Type: has_many
439
440 Related object: L<Koha::Schema::Result::Branchtransfer>
441
442 =cut
443
444 __PACKAGE__->has_many(
445   "branchtransfers",
446   "Koha::Schema::Result::Branchtransfer",
447   { "foreign.itemnumber" => "self.itemnumber" },
448   { cascade_copy => 0, cascade_delete => 0 },
449 );
450
451 =head2 course_item
452
453 Type: might_have
454
455 Related object: L<Koha::Schema::Result::CourseItem>
456
457 =cut
458
459 __PACKAGE__->might_have(
460   "course_item",
461   "Koha::Schema::Result::CourseItem",
462   { "foreign.itemnumber" => "self.itemnumber" },
463   { cascade_copy => 0, cascade_delete => 0 },
464 );
465
466 =head2 creator_batches
467
468 Type: has_many
469
470 Related object: L<Koha::Schema::Result::CreatorBatch>
471
472 =cut
473
474 __PACKAGE__->has_many(
475   "creator_batches",
476   "Koha::Schema::Result::CreatorBatch",
477   { "foreign.item_number" => "self.itemnumber" },
478   { cascade_copy => 0, cascade_delete => 0 },
479 );
480
481 =head2 hold_fill_target
482
483 Type: might_have
484
485 Related object: L<Koha::Schema::Result::HoldFillTarget>
486
487 =cut
488
489 __PACKAGE__->might_have(
490   "hold_fill_target",
491   "Koha::Schema::Result::HoldFillTarget",
492   { "foreign.itemnumber" => "self.itemnumber" },
493   { cascade_copy => 0, cascade_delete => 0 },
494 );
495
496 =head2 holdingbranch
497
498 Type: belongs_to
499
500 Related object: L<Koha::Schema::Result::Branch>
501
502 =cut
503
504 __PACKAGE__->belongs_to(
505   "holdingbranch",
506   "Koha::Schema::Result::Branch",
507   { branchcode => "holdingbranch" },
508   {
509     is_deferrable => 1,
510     join_type     => "LEFT",
511     on_delete     => "RESTRICT",
512     on_update     => "CASCADE",
513   },
514 );
515
516 =head2 homebranch
517
518 Type: belongs_to
519
520 Related object: L<Koha::Schema::Result::Branch>
521
522 =cut
523
524 __PACKAGE__->belongs_to(
525   "homebranch",
526   "Koha::Schema::Result::Branch",
527   { branchcode => "homebranch" },
528   {
529     is_deferrable => 1,
530     join_type     => "LEFT",
531     on_delete     => "RESTRICT",
532     on_update     => "CASCADE",
533   },
534 );
535
536 =head2 issues
537
538 Type: has_many
539
540 Related object: L<Koha::Schema::Result::Issue>
541
542 =cut
543
544 __PACKAGE__->has_many(
545   "issues",
546   "Koha::Schema::Result::Issue",
547   { "foreign.itemnumber" => "self.itemnumber" },
548   { cascade_copy => 0, cascade_delete => 0 },
549 );
550
551 =head2 old_issues
552
553 Type: has_many
554
555 Related object: L<Koha::Schema::Result::OldIssue>
556
557 =cut
558
559 __PACKAGE__->has_many(
560   "old_issues",
561   "Koha::Schema::Result::OldIssue",
562   { "foreign.itemnumber" => "self.itemnumber" },
563   { cascade_copy => 0, cascade_delete => 0 },
564 );
565
566 =head2 old_reserves
567
568 Type: has_many
569
570 Related object: L<Koha::Schema::Result::OldReserve>
571
572 =cut
573
574 __PACKAGE__->has_many(
575   "old_reserves",
576   "Koha::Schema::Result::OldReserve",
577   { "foreign.itemnumber" => "self.itemnumber" },
578   { cascade_copy => 0, cascade_delete => 0 },
579 );
580
581 =head2 reserves
582
583 Type: has_many
584
585 Related object: L<Koha::Schema::Result::Reserve>
586
587 =cut
588
589 __PACKAGE__->has_many(
590   "reserves",
591   "Koha::Schema::Result::Reserve",
592   { "foreign.itemnumber" => "self.itemnumber" },
593   { cascade_copy => 0, cascade_delete => 0 },
594 );
595
596 =head2 serialitem
597
598 Type: might_have
599
600 Related object: L<Koha::Schema::Result::Serialitem>
601
602 =cut
603
604 __PACKAGE__->might_have(
605   "serialitem",
606   "Koha::Schema::Result::Serialitem",
607   { "foreign.itemnumber" => "self.itemnumber" },
608   { cascade_copy => 0, cascade_delete => 0 },
609 );
610
611
612 # Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-10-24 09:58:16
613 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2slVK/FjcRDiYLeufoOFQQ
614
615 sub biblioitem {
616     my ( $self ) = @_;
617     my @biblioitems = $self->biblioitemnumber;
618     return $biblioitems[0];
619 }
620
621 sub effective_itemtype {
622     my ( $self ) = @_;
623
624     my $pref = $self->result_source->schema->resultset('Systempreference')->find('item-level_itypes');
625     if ( $pref->value() ) {
626         return $self->itype();
627     } else {
628         return $self->biblioitem()->itemtype();
629     }
630 }
631
632 1;