]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Storage/CDBI.pm
make sure we are not trying to use a "modern" class::dbi
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Storage / CDBI.pm
1 package OpenILS::Application::Storage::CDBI;
2 use base qw/Class::DBI/;
3 use Class::DBI;
4 use Class::DBI::AbstractSearch;
5
6 use OpenILS::Application::Storage::CDBI::actor;
7 use OpenILS::Application::Storage::CDBI::action;
8 use OpenILS::Application::Storage::CDBI::booking;
9 use OpenILS::Application::Storage::CDBI::asset;
10 use OpenILS::Application::Storage::CDBI::authority;
11 use OpenILS::Application::Storage::CDBI::biblio;
12 use OpenILS::Application::Storage::CDBI::config;
13 use OpenILS::Application::Storage::CDBI::metabib;
14 use OpenILS::Application::Storage::CDBI::money;
15 use OpenILS::Application::Storage::CDBI::permission;
16 use OpenILS::Application::Storage::CDBI::container;
17
18 use OpenSRF::Utils::JSON;
19 use OpenSRF::Utils::Logger qw(:level);
20 use OpenSRF::EX qw/:try/;
21
22 our $VERSION = 1;
23 my $log = 'OpenSRF::Utils::Logger';
24
25 if ($Class::DBI::VERSION gt '3.0.1') {
26     $log->error("Your version of Class::DBI, $Class::DBI::VERSION, is too new and incompatable with Evergreen.  You will need to downgrade to version 3.0.1"); 
27     die("Your version of Class::DBI, $Class::DBI::VERSION, is too new and incompatable with Evergreen.  You will need to downgrade to version 3.0.1"); 
28 }
29
30 sub child_init {
31         my $self = shift;
32
33         $log->debug("Creating ImaDBI Querys", DEBUG);
34         __PACKAGE__->set_sql( 'OILSFastSearch', <<"     SQL", 'Main');
35                 SELECT  %s
36                   FROM  %s
37                   WHERE %s = ?
38         SQL
39
40         __PACKAGE__->set_sql( 'OILSFastOrderedSearchLike', <<"  SQL", 'Main');
41                 SELECT  %s
42                   FROM  %s
43                   WHERE %s LIKE ?
44                   ORDER BY %s
45         SQL
46
47         __PACKAGE__->set_sql( 'OILSFastOrderedSearch', <<"      SQL", 'Main');
48                 SELECT  %s
49                   FROM  %s
50                   WHERE %s = ?
51                   ORDER BY %s
52         SQL
53
54         $log->debug("Calling Driver child_init", DEBUG);
55         $self->SUPER::child_init(@_);
56
57 }
58
59 sub fast_flesh_sth {
60         my $class = shift;
61         $class = ref($class) || $class;
62
63         my $field = shift;
64         my $value = shift;
65         my $order = shift;
66         my $like = shift;
67
68
69         if (!(defined($order) and ref($order) and ref($order) eq 'HASH')) {
70                 if (defined($value) and ref($value) and ref($value) eq 'HASH') {
71                         $order = $value;
72                         $value = undef;
73                 } else {
74                         $order = { order_by => $class->columns('Primary') }
75                 }
76         }
77
78         unless (defined $value) {
79                 $value = $field;
80                 ($field) = $class->columns('Primary');
81         }
82
83         unless (defined $field) {
84                 ($field) = $class->columns('Primary');
85         }
86
87         unless ($order->{order_by}) {
88                 $order = { order_by => $class->columns('Primary') }
89         }
90
91         my $fm_class = 'Fieldmapper::'.$class;
92         my $field_list = join ',', $class->columns('Essential');
93         
94         my $sth;
95         if (!$like) {
96                 $sth = $class->sql_OILSFastOrderedSearch( $field_list, $class->table, $field, $order->{order_by});
97         } else {
98                 $sth = $class->sql_OILSFastOrderedSearchLike( $field_list, $class->table, $field, $order->{order_by});
99         }
100         $sth->execute($value);
101         return $sth;
102 }
103
104 sub fast_flesh {
105         my $self = shift;
106         return map $class->construct($_), $self->fast_flesh_sth(@_)->fetchall_hash;
107 }
108
109 sub fast_fieldmapper {
110         my $self = shift;
111         my $id = shift;
112         my $col = shift;
113         my $like = shift;
114         my $options = shift;
115         my $class = ref($self) || $self;
116         my $fm_class = 'Fieldmapper::'.$class;
117         my @fms;
118         $log->debug("fast_fieldmapper() ==> Retrieving $fm_class", INTERNAL);
119         if ($like < 2) {
120                 for my $hash ($self->fast_flesh_sth( $col, "$id", { order_by => $col }, $like )->fetchall_hash) {
121                         my $fm = $fm_class->new;
122                         for my $field ( $fm_class->real_fields ) {
123                                 $fm->$field( $$hash{$field} );
124                         }
125                         push @fms, $fm;
126                 }
127         } else {
128                 my $search_type = 'search';
129                 if ($like == 2) {
130                         $search_type = 'search_fts'
131                 } elsif ($like == 3) {
132                         $search_type = 'search_regex'
133                 }
134
135                 for my $obj ($class->$search_type({ $col => $id}, $options)) {
136                         push @fms, $obj->to_fieldmapper;
137                 }
138         }
139         return @fms;
140 }
141
142 sub retrieve {
143         my $self = shift;
144         my $arg = shift;
145         if (ref($arg) &&
146                 (UNIVERSAL::isa($arg => 'Fieldmapper') ||
147                  UNIVERSAL::isa($arg => 'Class::DBI')) ) {
148                 my ($col) = $self->primary_column;
149                 $log->debug("Using field $col as the primary key", INTERNAL);
150                 $arg = $arg->$col;
151         } elsif (ref $arg) {
152                 my ($col) = $self->primary_column;
153                 $log->debug("Using field $col as the primary key", INTERNAL);
154                 $arg = $arg->{$col};
155         }
156                 
157         $log->debug("Retrieving $self with $arg", INTERNAL);
158         my $rec;
159         try {
160                 $rec = $self->SUPER::retrieve("$arg");
161         } catch Error with {
162                 $log->debug("Could not retrieve $self with $arg! -- ".shift(), DEBUG);
163                 return undef;
164         };
165         return $rec;
166 }
167
168 sub to_fieldmapper {
169         my $obj = shift;
170         my $class = ref($obj) || $obj;
171
172         my $fm_class = 'Fieldmapper::'.$class;
173         my $fm = $fm_class->new;
174
175         if (ref($obj)) {
176                 for my $field ( $fm->real_fields ) {
177                         $fm->$field( ''.$obj->$field );
178                 }
179         }
180
181         return $fm;
182 }
183
184 sub merge {
185         my $self = shift;
186         my $search = shift;
187         my $arg = shift;
188
189         delete $$arg{$_} for (keys %$search);
190
191         $log->debug("CDBI->merge: \$search is $search (".ref($search)." : ".join(',',map{"$_ => $$search{$_}"}keys(%$search)).")",DEBUG);
192         $log->debug("CDBI->merge: \$arg is $arg (".ref($arg)." : ".join(',',map{"$_ => $$arg{$_}"}keys(%$arg)).")",DEBUG);
193
194         my @objs = ($self);
195         @objs = $self->search_where($search) unless (ref $self);
196
197         if (@objs == 1) {
198                 $objs[0]->update($arg);
199                 return $objs[0];
200         } elsif (@objs == 0) {
201                 return $self->create({%$search,%$arg});
202         } else {
203                 throw OpenSRF::EX::WARN ("Non-unique search key for merge.  Perhaps you meant to use remote_update?");
204         }
205 }
206
207 sub remote_update {
208         my $self = shift;
209         my $search = shift;
210         my $arg = shift;
211
212         delete $$arg{$_} for (keys %$search);
213
214         $log->debug("CDBI->remote_update: \$search is $search (".ref($search)." : ".join(',',map{"$_ => $$search{$_}"}keys(%$search)).")",DEBUG);
215         $log->debug("CDBI->remote_update: \$arg is $arg (".ref($arg)." : ".join(',',map{"$_ => $$arg{$_}"}keys(%$arg)).")",DEBUG);
216
217 #       my @objs = $self->search_where($search);
218 #       throw OpenSRF::EX::WARN ("No objects found for remote_update.  Perhaps you meant to use merge?")
219 #               if (@objs == 0);
220
221 #       $_->update($arg) for (@objs);
222 #       return scalar(@objs);
223
224         my @finds = sort keys %$search;
225         my @sets = sort keys %$arg;
226
227         my @find_vals = @$search{@finds};
228         my @set_vals = @$arg{@sets};
229
230         my $sql = 'UPDATE %s SET %s WHERE %s';
231
232         my $table = $self->table;
233         my $set = join(', ', map { "$_=?" } @sets);
234         my $where = join(', ', map { "$_=?" } @finds);
235
236         my $sth = $self->db_Main->prepare(sprintf($sql, $table, $set, $where));
237         $sth->execute(@set_vals,@find_vals);
238         return $sth->rows;
239
240 }
241
242 sub create {
243         my $self = shift;
244         my $arg = shift;
245
246         $log->debug("CDBI->create: \$arg is $arg (".ref($arg)." : ".OpenSRF::Utils::JSON->perl2JSON($arg).")",DEBUG);
247
248         if (ref($arg) && UNIVERSAL::isa($arg => 'Fieldmapper')) {
249                 return $self->create_from_fieldmapper($arg,@_);
250         }
251
252         return $self->SUPER::create($arg,@_);
253 }
254
255 sub create_from_fieldmapper {
256         my $obj = shift;
257         my $fm = shift;
258         my @params = @_;
259
260         $log->debug("Creating node of type ".ref($fm), DEBUG);
261
262         my $class = ref($obj) || $obj;
263         my ($primary) = $class->columns('Primary');
264
265         if (ref($fm) &&UNIVERSAL::isa($fm => 'Fieldmapper')) {
266                 my %hash = map { defined $fm->$_ ?
267                                         ($_ => $fm->$_) :
268                                         ()
269                                 } grep { $_ ne $primary } $class->columns('Essential');
270
271                 if ($class->find_column( 'last_xact_id' )) {
272                         if ($OpenILS::Application::Storage::IGNORE_XACT_ID_FAILURE) {
273                                 $hash{last_xact_id} = 'unknown.'.time.'.'.$$.'.'.rand($$);
274                         } else {
275                                 my $xact_id = $class->current_xact_id;
276                                 throw Error unless ($xact_id);
277                                 $hash{last_xact_id} = $xact_id;
278                         }
279                 }
280
281                 return $class->create( \%hash, @params );
282         } else {
283                 return undef;
284         }
285 }
286
287 sub delete {
288         my $self = shift;
289         my $arg = shift;
290         my $orig = $self;
291
292         my $class = ref($self) || $self;
293
294         $self = $self->retrieve($arg) if (!ref($self));
295         unless (defined $self) {
296                 $log->debug("ARG! Couldn't retrieve record ".$arg->id, DEBUG);
297                 throw OpenSRF::EX::WARN ("ARG! Couldn't retrieve record ");
298         }
299
300         if ($class->find_column( 'last_xact_id' )) {
301                 my $xact_id = $self->current_xact_id;
302                 
303                 throw Error ("Deleting from $class requires a transaction be established")
304                         unless ($xact_id);
305                 
306                 throw Error ("The row you are attempting to delete has been changed since you read it")
307                         unless ( $orig->last_xact_id eq $self->last_xact_id);
308
309                 $self->last_xact_id( $class->current_xact_id );
310                 $self->SUPER::update;
311         }
312
313         $self->SUPER::delete;
314
315         return 1;
316 }
317
318 sub debug_object {
319         my $obj = shift;
320         my $string = '';
321
322         $string .= "Object type:\t".ref($obj)."\n";
323         $string .= "Object string:\t$obj\n";
324
325         if (ref($obj) && UNIVERSAL::isa($obj => 'Fieldmapper')) {
326                 $string .= "Object fields:\n";
327                 for my $col ($obj->real_fields()) {
328                         $string .= "\t$col\t=> ".$obj->$col."\n";
329                 }
330         } elsif (ref($obj) && UNIVERSAL::isa($obj => 'Class::DBI')) {
331                 $string .= "Object cols:\n";
332                 for my $col ($obj->columns('All')) {
333                         $string .= "\t$col\t=> ".$obj->$col."\n";
334                 }
335         } elsif (ref($obj) && UNIVERSAL::isa($obj => 'HASH')) {
336                 $string .= "Object keys and vals:\n";
337                 for my $col (keys %$obj) {
338                         $string .= "\t$col\t=> $$obj{$col}\n";
339                 }
340         }
341
342         $string .= "\n";
343         
344         $log->debug($string,DEBUG);
345 }
346
347
348 sub update {
349         my $self = shift;
350         my $arg = shift;
351
352         $log->debug("Attempting to update using $arg", DEBUG) if ($arg);
353
354         if (ref($arg)) {
355                 $self = $self->modify_from_fieldmapper($arg);
356                 unless (defined $self) {
357                         $log->debug("Modification of $arg seems to have failed....", DEBUG);
358                         return undef;
359                 }
360         }
361
362         $log->debug("Calling Class::DBI->update on modified object $self", DEBUG);
363
364         #debug_object($self);
365
366         return $self->SUPER::update if ($self->is_changed);
367         return 0;
368 }
369
370 sub modify_from_fieldmapper {
371         my $obj = shift;
372         my $fm = shift;
373         my $orig = $obj;
374
375         #debug_object($obj);
376         #debug_object($fm);
377
378         $log->debug("Modifying object using fieldmapper", DEBUG);
379
380         my $class = ref($obj) || $obj;
381         my ($primary) = $class->columns('Primary');
382
383
384         if (!ref($obj)) {
385                 $obj = $class->retrieve($fm);
386                 #debug_object($obj);
387                 unless ($obj) {
388                         $log->debug("Retrieve of $class using $fm (".$fm->id.") failed! -- ".shift(), ERROR);
389                         throw OpenSRF::EX::WARN ("No $class with id of ".$fm->id."!!");
390                 }
391         }
392
393         my %hash;
394         
395         if (ref($fm) and UNIVERSAL::isa($fm => 'Fieldmapper')) {
396                 %hash = map { ($_ => $fm->$_) } grep { $_ ne $primary } $class->columns('Essential');
397                 delete $hash{passwd} if ($fm->isa('Fieldmapper::actor::user'));
398         } else {
399                 %hash = %{$fm};
400         }
401
402         my $au = $obj->autoupdate;
403         $obj->autoupdate(0);
404         
405         #debug_object($obj);
406
407         for my $field ( keys %hash ) {
408                 $obj->$field( $hash{$field} ) if ($obj->$field ne $hash{$field});
409                 $log->debug("Setting field $field on $obj to $hash{$field}",INTERNAL);
410         }
411
412         if ($class->find_column( 'last_xact_id' ) and $obj->is_changed) {
413                 my ($xact_id) = OpenILS::Application::Storage->method_lookup('open-ils.storage.transaction.current')->run();
414                 throw Error ("Updating $class requires a transaction be established")
415                         unless ($xact_id);
416                 throw Error ("The row you are attempting to delete has been changed since you read it")
417                         unless ( $fm->last_xact_id eq $obj->last_xact_id);
418                 $obj->last_xact_id( $xact_id );
419         } else {
420                 $obj->autoupdate($au)
421         }
422
423         return $obj;
424 }
425
426
427
428         #-------------------------------------------------------------------------------
429         actor::user->has_a( home_ou => 'actor::org_unit' );
430         actor::user->has_a( card => 'actor::card' );
431         actor::user->has_a( standing => 'config::standing' );
432         actor::user->has_a( profile => 'permission::grp_tree' );
433         actor::user->has_a( mailing_address => 'actor::user_address' );
434         actor::user->has_a( billing_address => 'actor::user_address' );
435         actor::user->has_a( ident_type => 'config::identification_type' );
436         actor::user->has_a( ident_type2 => 'config::identification_type' );
437         actor::user->has_a( net_access_level => 'config::net_access_level' );
438
439         actor::user_address->has_a( usr => 'actor::user' );
440         
441         actor::card->has_a( usr => 'actor::user' );
442         
443         actor::workstation->has_a( owning_lib => 'actor::org_unit' );
444         actor::org_unit::closed_date->has_a( org_unit => 'actor::org_unit' );
445         actor::org_unit_setting->has_a( org_unit => 'actor::org_unit' );
446
447         actor::usr_note->has_a( usr => 'actor::user' );
448         actor::user->has_many( notes => 'actor::usr_note' );
449
450         actor::user_standing_penalty->has_a( usr => 'actor::user' );
451         actor::user->has_many( standing_penalties => 'actor::user_standing_penalty' );
452
453         actor::org_unit->has_a( parent_ou => 'actor::org_unit' );
454         actor::org_unit->has_a( ou_type => 'actor::org_unit_type' );
455         actor::org_unit->has_a( ill_address => 'actor::org_address' );
456         actor::org_unit->has_a( holds_address => 'actor::org_address' );
457         actor::org_unit->has_a( mailing_address => 'actor::org_address' );
458         actor::org_unit->has_a( billing_address => 'actor::org_address' );
459         actor::org_unit->has_many( children => 'actor::org_unit' => 'parent_ou' );
460         actor::org_unit->has_many( workstations => 'actor::workstation' );
461         actor::org_unit->has_many( closed_dates => 'actor::org_unit::closed_date' );
462         actor::org_unit->has_many( settings => 'actor::org_unit_setting' );
463         #actor::org_unit->might_have( hours_of_operation => 'actor::org_unit::hours_of_operation' );
464
465         actor::org_unit_type->has_a( parent => 'actor::org_unit_type' );
466         actor::org_unit_type->has_many( children => 'actor::org_unit_type' => 'parent' );
467
468         actor::org_address->has_a( org_unit => 'actor::org_unit' );
469         actor::org_unit->has_many( addresses => 'actor::org_address' );
470
471         action::transit_copy->has_a( source => 'actor::org_unit' );
472         action::transit_copy->has_a( dest => 'actor::org_unit' );
473         action::transit_copy->has_a( copy_status => 'config::copy_status' );
474
475         action::hold_transit_copy->has_a( source => 'actor::org_unit' );
476         action::hold_transit_copy->has_a( dest => 'actor::org_unit' );
477         action::hold_transit_copy->has_a( copy_status => 'config::copy_status' );
478         action::hold_transit_copy->has_a( hold => 'action::hold_request' );
479
480         action::hold_request->has_many( transits => 'action::hold_transit_copy' );
481
482         actor::stat_cat_entry->has_a( stat_cat => 'actor::stat_cat' );
483         actor::stat_cat->has_a( owner => 'actor::org_unit' );
484         actor::stat_cat->has_many( entries => 'actor::stat_cat_entry' );
485         actor::stat_cat_entry_user_map->has_a( stat_cat => 'actor::stat_cat' );
486         actor::stat_cat_entry_user_map->has_a( stat_cat_entry => 'actor::stat_cat_entry' );
487         actor::stat_cat_entry_user_map->has_a( target_usr => 'actor::user' );
488
489         asset::stat_cat_entry->has_a( stat_cat => 'asset::stat_cat' );
490         asset::stat_cat->has_a( owner => 'actor::org_unit' );
491         asset::stat_cat->has_many( entries => 'asset::stat_cat_entry' );
492         asset::stat_cat_entry_copy_map->has_a( stat_cat => 'asset::stat_cat' );
493         asset::stat_cat_entry_copy_map->has_a( stat_cat_entry => 'asset::stat_cat_entry' );
494         asset::stat_cat_entry_copy_map->has_a( owning_copy => 'asset::copy' );
495
496         action::survey_response->has_a( usr => 'actor::user' );
497         action::survey_response->has_a( survey => 'action::survey' );
498         action::survey_response->has_a( question => 'action::survey_question' );
499         action::survey_response->has_a( answer => 'action::survey_answer' );
500
501         action::survey_question->has_a( survey => 'action::survey' );
502
503         action::survey_answer->has_a( question => 'action::survey_question' );
504
505         asset::copy_note->has_a( owning_copy => 'asset::copy' );
506         asset::copy_note->has_a( creator => 'actor::user' );
507
508         actor::user->has_many( stat_cat_entries => [ 'actor::stat_cat_entry_user_map' => 'stat_cat_entry' ] );
509         actor::user->has_many( stat_cat_entry_user_maps => 'actor::stat_cat_entry_user_map' );
510
511         asset::copy->has_many( stat_cat_entries => [ 'asset::stat_cat_entry_copy_map' => 'stat_cat_entry' ] );
512         asset::copy->has_many( stat_cat_entry_copy_maps => 'asset::stat_cat_entry_copy_map' );
513
514         asset::copy->has_a( call_number => 'asset::call_number' );
515         asset::copy->has_a( creator => 'actor::user' );
516         asset::copy->has_a( editor => 'actor::user' );
517         asset::copy->has_a( status => 'config::copy_status' );
518         asset::copy->has_a( location => 'asset::copy_location' );
519         asset::copy->has_a( circ_lib => 'actor::org_unit' );
520
521         asset::call_number_note->has_a( call_number => 'asset::call_number' );
522
523         asset::call_number->has_a( record => 'biblio::record_entry' );
524         asset::call_number->has_a( creator => 'actor::user' );
525         asset::call_number->has_a( editor => 'actor::user' );
526         asset::call_number->has_a( owning_lib => 'actor::org_unit' );
527
528         authority::record_note->has_a( record => 'authority::record_entry' );
529         biblio::record_note->has_a( record => 'biblio::record_entry' );
530         
531         authority::record_entry->has_a( creator => 'actor::user' );
532         authority::record_entry->has_a( editor => 'actor::user' );
533         biblio::record_entry->has_a( creator => 'actor::user' );
534         biblio::record_entry->has_a( editor => 'actor::user' );
535         
536         metabib::metarecord->has_a( master_record => 'biblio::record_entry' );
537         
538         authority::record_descriptor->has_a( record => 'authority::record_entry' );
539         metabib::record_descriptor->has_a( record => 'biblio::record_entry' );
540         
541         authority::full_rec->has_a( record => 'authority::record_entry' );
542         metabib::full_rec->has_a( record => 'biblio::record_entry' );
543         
544         metabib::title_field_entry->has_a( source => 'biblio::record_entry' );
545         metabib::title_field_entry->has_a( field => 'config::metabib_field' );
546
547         metabib::identifier_field_entry->has_a( source => 'biblio::record_entry' );
548         metabib::identifier_field_entry->has_a( field => 'config::metabib_field' );
549         
550         metabib::author_field_entry->has_a( source => 'biblio::record_entry' );
551         metabib::author_field_entry->has_a( field => 'config::metabib_field' );
552         
553         metabib::subject_field_entry->has_a( source => 'biblio::record_entry' );
554         metabib::subject_field_entry->has_a( field => 'config::metabib_field' );
555         
556         metabib::keyword_field_entry->has_a( source => 'biblio::record_entry' );
557         metabib::keyword_field_entry->has_a( field => 'config::metabib_field' );
558         
559         metabib::series_field_entry->has_a( source => 'biblio::record_entry' );
560         metabib::series_field_entry->has_a( field => 'config::metabib_field' );
561         
562         metabib::metarecord_source_map->has_a( metarecord => 'metabib::metarecord' );
563         metabib::metarecord_source_map->has_a( source => 'biblio::record_entry' );
564
565         action::circulation->has_a( usr => 'actor::user' );
566         actor::user->has_many( circulations => 'action::circulation' => 'usr' );
567
568         booking::resource_attr_map->has_a( resource => 'booking::resource' );
569
570         booking::resource->has_a( owner => 'actor::org_unit' );
571         booking::resource->has_a( type => 'booking::resource_type' );
572         booking::resource_type->has_a( owner => 'actor::org_unit' );
573
574         booking::reservation->has_a( usr => 'actor::user' );
575         actor::user->has_many( reservations => 'booking::reservation' => 'usr' );
576         
577         action::circulation->has_a( circ_staff => 'actor::user' );
578         actor::user->has_many( performed_circulations => 'action::circulation' => 'circ_staff' );
579
580         action::circulation->has_a( checkin_staff => 'actor::user' );
581         actor::user->has_many( checkins => 'action::circulation' => 'checkin_staff' );
582
583         action::circulation->has_a( target_copy => 'asset::copy' );
584         asset::copy->has_many( circulations => 'action::circulation' => 'target_copy' );
585
586         booking::reservation->has_a( pickup_lib => 'actor::org_unit' );
587
588         action::circulation->has_a( circ_lib => 'actor::org_unit' );
589         actor::org_unit->has_many( circulations => 'action::circulation' => 'circ_lib' );
590         
591         action::circulation->has_a( checkin_lib => 'actor::org_unit' );
592         actor::org_unit->has_many( checkins => 'action::circulation' => 'checkin_lib' );
593
594         money::billable_transaction->has_a( usr => 'actor::user' );
595         #money::billable_transaction->might_have( circulation => 'action::circulation' );
596         #money::billable_transaction->might_have( grocery => 'money::grocery' );
597         actor::user->has_many( billable_transactions => 'action::circulation' => 'usr' );
598         
599         
600         #-------------------------------------------------------------------------------
601         actor::user->has_many( survey_responses => 'action::survey_response' );
602         actor::user->has_many( addresses => 'actor::user_address' );
603         actor::user->has_many( cards => 'actor::card' );
604
605         actor::org_unit->has_many( users => 'actor::user' );
606
607         action::survey->has_many( questions => 'action::survey_question' );
608         action::survey->has_many( responses => 'action::survey_response' );
609         
610         action::survey_question->has_many( answers => 'action::survey_answer' );
611         action::survey_question->has_many( responses => 'action::survey_response' );
612
613         action::survey_answer->has_many( responses => 'action::survey_response' );
614
615         asset::copy->has_many( notes => 'asset::copy_note' );
616         asset::call_number->has_many( copies => 'asset::copy' );
617         asset::call_number->has_many( notes => 'asset::call_number_note' );
618
619         authority::record_entry->has_many( record_descriptor => 'authority::record_descriptor' );
620         authority::record_entry->has_many( notes => 'authority::record_note' );
621
622         biblio::record_entry->has_many( record_descriptor => 'metabib::record_descriptor' );
623         biblio::record_entry->has_many( notes => 'biblio::record_note' );
624         biblio::record_entry->has_many( call_numbers => 'asset::call_number' );
625         biblio::record_entry->has_many( full_record_entries => 'metabib::full_rec' );
626         biblio::record_entry->has_many( title_field_entries => 'metabib::title_field_entry' );
627         biblio::record_entry->has_many( identifier_field_entries => 'metabib::identifier_field_entry' );
628         biblio::record_entry->has_many( author_field_entries => 'metabib::author_field_entry' );
629         biblio::record_entry->has_many( subject_field_entries => 'metabib::subject_field_entry' );
630         biblio::record_entry->has_many( keyword_field_entries => 'metabib::keyword_field_entry' );
631         biblio::record_entry->has_many( series_field_entries => 'metabib::series_field_entry' );
632
633         metabib::metarecord->has_many( source_records => [ 'metabib::metarecord_source_map' => 'source'] );
634         biblio::record_entry->has_many( metarecords => [ 'metabib::metarecord_source_map' => 'metarecord'] );
635
636         money::billing->has_a( xact => 'money::billable_transaction' );
637         money::payment->has_a( xact => 'money::billable_transaction' );
638
639         money::billable_transaction->has_many( billings => 'money::billing' );
640         money::billable_transaction->has_many( payments => 'money::payment' );
641
642         action::circulation->has_many( billings => 'money::billing' => 'xact' );
643         action::circulation->has_many( payments => 'money::payment' => 'xact' );
644         #action::circulation->might_have( billable_transaction => 'money::billable_transaction' );
645         #action::open_circulation->might_have( circulation => 'action::circulation' );
646
647         booking::reservation->has_many( billings => 'money::billing' => 'xact' );
648         booking::reservation->has_many( payments => 'money::payment' => 'xact' );
649
650         action::in_house_use->has_a( org_unit => 'actor::org_unit' );
651         action::in_house_use->has_a( staff => 'actor::user' );
652         action::in_house_use->has_a( item => 'asset::copy' );
653
654         action::non_cataloged_circulation->has_a( circ_lib => 'actor::org_unit' );
655         action::non_cataloged_circulation->has_a( item_type => 'config::non_cataloged_type' );
656         action::non_cataloged_circulation->has_a( patron => 'actor::user' );
657         action::non_cataloged_circulation->has_a( staff => 'actor::user' );
658
659         money::grocery->has_many( billings => 'money::billing' => 'xact' );
660         money::grocery->has_many( payments => 'money::payment' => 'xact' );
661         #money::grocery->might_have( billable_transaction => 'money::billable_transaction' );
662
663         #money::payment->might_have( cash_payment => 'money::cash_payment' );
664         #money::payment->might_have( check_payment => 'money::check_payment' );
665         #money::payment->might_have( credit_card_payment => 'money::credit_card_payment' );
666         #money::payment->might_have( forgive_payment => 'money::forgive_payment' );
667         #money::payment->might_have( work_payment => 'money::work_payment' );
668         #money::payment->might_have( credit_payment => 'money::credit_payment' );
669
670         money::cash_payment->has_a( xact => 'money::billable_transaction' );
671         money::cash_payment->has_a( accepting_usr => 'actor::user' );
672         #money::cash_payment->might_have( payment => 'money::payment' );
673
674         money::check_payment->has_a( xact => 'money::billable_transaction' );
675         money::check_payment->has_a( accepting_usr => 'actor::user' );
676         #money::check_payment->might_have( payment => 'money::payment' );
677
678         money::credit_card_payment->has_a( xact => 'money::billable_transaction' );
679         money::credit_card_payment->has_a( accepting_usr => 'actor::user' );
680         #money::credit_card_payment->might_have( payment => 'money::payment' );
681
682         money::forgive_payment->has_a( xact => 'money::billable_transaction' );
683         money::forgive_payment->has_a( accepting_usr => 'actor::user' );
684         #money::forgive_payment->might_have( payment => 'money::payment' );
685
686         money::work_payment->has_a( xact => 'money::billable_transaction' );
687         money::work_payment->has_a( accepting_usr => 'actor::user' );
688         #money::work_payment->might_have( payment => 'money::payment' );
689
690         money::goods_payment->has_a( xact => 'money::billable_transaction' );
691         money::goods_payment->has_a( accepting_usr => 'actor::user' );
692         #money::goods_payment->might_have( payment => 'money::payment' );
693
694         money::credit_payment->has_a( xact => 'money::billable_transaction' );
695         money::credit_payment->has_a( accepting_usr => 'actor::user' );
696         #money::credit_payment->might_have( payment => 'money::payment' );
697
698         permission::grp_tree->has_a( parent => 'permission::grp_tree' );
699         permission::grp_tree->has_many( children => 'permission::grp_tree' => 'parent' );
700
701         permission::grp_perm_map->has_a( grp => 'permission::grp_tree' );
702         permission::grp_perm_map->has_a(  perm => 'permission::perm_list' );
703         permission::grp_perm_map->has_a(  depth => 'actor::org_unit_type' );
704         
705         permission::usr_perm_map->has_a( usr => 'actor::user' );
706         permission::usr_perm_map->has_a(  perm => 'permission::perm_list' );
707         permission::usr_perm_map->has_a(  depth => 'actor::org_unit_type' );
708         
709         permission::usr_grp_map->has_a(  usr => 'actor::user' );
710         permission::usr_grp_map->has_a(  grp => 'permission::grp_tree' );
711
712         action::hold_notification->has_a(  hold => 'action::hold_request' );
713         
714         action::hold_copy_map->has_a(  hold => 'action::hold_request' );
715         action::hold_copy_map->has_a(  target_copy => 'asset::copy' );
716
717         action::unfulfilled_hold_list->has_a(  current_copy => 'asset::copy' );
718         action::unfulfilled_hold_list->has_a(  hold => 'action::hold_request' );
719         action::unfulfilled_hold_list->has_a(  circ_lib => 'actor::org_unit' );
720
721         action::hold_request->has_a(  current_copy => 'asset::copy' );
722         action::hold_request->has_a(  requestor => 'actor::user' );
723         action::hold_request->has_a(  usr => 'actor::user' );
724         action::hold_request->has_a(  fulfillment_staff => 'actor::user' );
725         action::hold_request->has_a(  pickup_lib => 'actor::org_unit' );
726         action::hold_request->has_a(  request_lib => 'actor::org_unit' );
727         action::hold_request->has_a(  fulfillment_lib => 'actor::org_unit' );
728         action::hold_request->has_a(  selection_ou => 'actor::org_unit' );
729
730         action::hold_request->has_many(  notifications => 'action::hold_notification' );
731         action::hold_request->has_many(  eligible_copies => [ 'action::hold_copy_map' => 'target_copy' ] );
732
733         asset::copy->has_many(  holds => [ 'action::hold_copy_map' => 'hold' ] );
734
735         container::biblio_record_entry_bucket->has_a( owner => 'actor::user' );
736         container::biblio_record_entry_bucket_item->has_a( bucket => 'container::biblio_record_entry_bucket' );
737         container::biblio_record_entry_bucket_item->has_a( target_biblio_record_entry => 'biblio::record_entry' );
738         container::biblio_record_entry_bucket->has_many( items => 'container::biblio_record_entry_bucket_item' );
739
740         container::user_bucket->has_a( owner => 'actor::user' );
741         container::user_bucket_item->has_a( bucket => 'container::user_bucket' );
742         container::user_bucket_item->has_a( target_user => 'actor::user' );
743         container::user_bucket->has_many( items => 'container::user_bucket_item' );
744
745         container::call_number_bucket->has_a( owner => 'actor::user' );
746         container::call_number_bucket_item->has_a( bucket => 'container::call_number_bucket' );
747         container::call_number_bucket_item->has_a( target_call_number => 'asset::call_number' );
748         container::call_number_bucket->has_many( items => 'container::call_number_bucket_item' );
749
750         container::copy_bucket->has_a( owner => 'actor::user' );
751         container::copy_bucket_item->has_a( bucket => 'container::copy_bucket' );
752         container::copy_bucket_item->has_a( target_copy => 'asset::copy' );
753         container::copy_bucket->has_many( items => 'container::copy_bucket_item' );
754
755
756 1;