From a0c4c21e61f3ea4bb65f857662bb5c28618c5563 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Mon, 9 Jan 2012 09:30:29 +0000 Subject: [PATCH] handle existing attr in overriden find(), sort device results --- Netdisco/lib/Netdisco/DB/ResultSet/Device.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Netdisco/lib/Netdisco/DB/ResultSet/Device.pm b/Netdisco/lib/Netdisco/DB/ResultSet/Device.pm index 34b06e18..45c05160 100644 --- a/Netdisco/lib/Netdisco/DB/ResultSet/Device.pm +++ b/Netdisco/lib/Netdisco/DB/ResultSet/Device.pm @@ -7,10 +7,12 @@ use NetAddr::IP::Lite ':lower'; # override the built-in so we can munge some columns sub find { - my ($set, $ip) = @_; + my ($set, $ip, $attr) = @_; + $attr ||= {}; return $set->SUPER::find($ip, { + %$attr, '+select' => [ \"replace(age(timestamp 'epoch' + uptime / 100 * interval '1 second', timestamp '1970-01-01 00:00:00-00')::text, 'mon', 'month')", \"to_char(last_discover, 'YYYY-MM-DD HH24:MI')", @@ -75,6 +77,7 @@ sub by_field { ], }, { + order_by => [qw/ me.dns me.ip /], join => 'device_ips', group_by => 'me.ip', } @@ -105,6 +108,7 @@ sub by_any { ], }, { + order_by => [qw/ me.dns me.ip /], join => 'device_ips', group_by => 'me.ip', }