[Koha-bugs] [Bug 11518] Add new method to Koha::Schema::Result::Item that will always return the correct itemtype

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Fri Jan 10 14:10:58 CET 2014


http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11518

--- Comment #4 from Kyle M Hall <kyle at bywatersolutions.com> ---
In the future we could even override $item->itype() to return the correct value
via system preference. Not sure if this would be a good idea or a bad one. In
some cases it would likely eliminate accidental bugs. From the DBIC FAQ:

How do I override a run time method (e.g. a relationship accessor)?
If you need access to the original accessor, then you must "wrap around" the
original method. You can do that either with Moose::Manual::MethodModifiers or
Class::Method::Modifiers. The code example works for both modules:

package Your::Schema::Group;
use Class::Method::Modifiers;

# ... declare columns ...

__PACKAGE__->has_many('group_servers', 'Your::Schema::GroupServer',
'group_id');
__PACKAGE__->many_to_many('servers', 'group_servers', 'server');

# if the server group is a "super group", then return all servers
# otherwise return only servers that belongs to the given group
around 'servers' => sub {
    my $orig = shift;
    my $self = shift;

    return $self->$orig(@_) unless $self->is_super_group;
    return $self->result_source->schema->resultset('Server')->all;
};

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list