https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28567
--- Comment #19 from Jonathan Druart <[email protected]> --- (In reply to Marcel de Rooy from comment #18) > (In reply to Jonathan Druart from comment #17) > > > In this case I would opt for the Koha::Objects instead of copying the same > > > code in controller scripts. > > > > > > Object:new > > > # Remove the arguments which exist, are not defined but NOT NULL > > > to > > > use the default value > > > my $columns_info = $schema->resultset( $class->_type > > > )->result_source->columns_info; > > > for my $column_name ( keys %$attributes ) { > > > my $c_info = $columns_info->{$column_name}; > > > next if $c_info->{is_nullable}; > > > next if not exists $attributes->{$column_name} or defined > > > $attributes->{$column_name}; > > > delete $attributes->{$column_name}; > > > } > > > Why not set $attributes->{$column_name} = $c_info->{default_value} if > > > defined and delete only if not? > > > > We just ignore if set. This is completely different code (we are dealing > > with NOT NULL values). What's the question exactly, what do you suggest? Can > > we discuss it somewhere else? :D > > This code comes into play since admin/branches calls: > my $library = Koha::Library->new > If Koha::Object->new here passed the default SQL value of 1, we could > eliminate the mentioned confusing construction. > Actually in the above comment even a reference to default value is made, but > the code does not do it. I am sorry, Marcel, but I still don't get it. Can you be more explicit, maybe provide a patch? Which "confusing construction" are you talking about? The map introduced by this patch? It's just simple and easy Perl code. In Koha::Object->new we are making the DBMS use the default value (so defined in the DB schema) by *removing* the key of the attributes that is "NOT NULL" *but* not defined! Based on that, what I understand from your suggestion would be to remove 'pickup_location' from the constructor if it's equal to '1'. But that would be very bad (what if the default value is modified later?), so I guess you had something else in mind :) -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list [email protected] https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
