# loop thru all fk and create linked records if needed
# fills remaining entries in $col_values
my $foreign_keys = $self->_getForeignKeys( { source => $source } );
+ my $col_names = {};
for my $fk ( @$foreign_keys ) {
# skip when FK points to itself: e.g. borrowers:guarantorid
next if $fk->{source} eq $source;
+
+ # If we have more than one FK on the same column, we only generate values for the first one
+ next
+ if scalar @{ $fk->{keys} } == 1
+ && exists $col_names->{ $fk->{keys}->[0]->{col_name} };
+
my $keys = $fk->{keys};
my $tbl = $fk->{source};
my $res = $self->_create_links( $tbl, $keys, $col_values, $value );
foreach( keys %$res ) { # save new values
$col_values->{$_} = $res->{$_};
}
+
+ $col_names->{ $fk->{keys}->[0]->{col_name} } = 1
+ if scalar @{ $fk->{keys} } == 1
}
# store this record and return hashref
# A column is not marked as FK, but a belongs_to relation is defined
my ( $source, $column ) = @_;
my $inconsistencies = {
- 'Item.biblionumber' => 1, #FIXME: Please remove me when I become FK
+ 'Item.biblionumber' => 1, #FIXME: Please remove me when I become FK
+ 'CheckoutRenewal.checkout_id' => 1, #FIXME: Please remove when issues and old_issues are merged
};
return $inconsistencies->{ "$source.$column" };
}
sub _gen_type {
return {
- tinyint => \&_gen_int,
+ tinyint => \&_gen_bool,
smallint => \&_gen_int,
mediumint => \&_gen_int,
integer => \&_gen_int,
};
};
+sub _gen_bool {
+ my ($self, $params) = @_;
+ return int( rand(2) );
+}
+
sub _gen_int {
my ($self, $params) = @_;
my $data_type = $params->{info}->{data_type};
sub _gen_default_values {
my ($self) = @_;
return {
+ BackgroundJob => {
+ context => '{}'
+ },
Borrower => {
login_attempts => 0,
gonenoaddress => undef,
lost => undef,
debarred => undef,
borrowernotes => '',
+ secret => undef,
+ password_expiration_date => undef,
},
Item => {
notforloan => 0,
Aqbookseller => {
tax_rate => 0,
discount => 0,
+ url => undef,
+ },
+ Aqbudget => {
+ sort1_authcat => undef,
+ sort2_authcat => undef,
},
AuthHeader => {
marcxml => '',
suggesteddate => dt_from_string()->ymd,
STATUS => 'ASKED'
},
+ ReturnClaim => {
+ issue_id => undef, # It should be a FK but we removed it
+ # We don't want to generate a random value
+ },
+ ImportItem => {
+ status => 'staged',
+ import_error => undef
+ },
+ SearchFilter => {
+ opac => 1,
+ staff_client => 1
+ },
};
}