1use utf8;
2package App::Netdisco::DB::Result::NodeWireless;
3
4
5use strict;
6use warnings;
7
8use NetAddr::MAC;
9
10use base 'App::Netdisco::DB::Result';
11__PACKAGE__->table("node_wireless");
12__PACKAGE__->add_columns(
13  "mac",
14  { data_type => "macaddr", is_nullable => 0 },
15  "uptime",
16  { data_type => "integer", is_nullable => 1 },
17  "maxrate",
18  { data_type => "integer", is_nullable => 1 },
19  "txrate",
20  { data_type => "integer", is_nullable => 1 },
21  "sigstrength",
22  { data_type => "integer", is_nullable => 1 },
23  "sigqual",
24  { data_type => "integer", is_nullable => 1 },
25  "rxpkt",
26  { data_type => "bigint", is_nullable => 1 },
27  "txpkt",
28  { data_type => "bigint", is_nullable => 1 },
29  "rxbyte",
30  { data_type => "bigint", is_nullable => 1 },
31  "txbyte",
32  { data_type => "bigint", is_nullable => 1 },
33  "time_last",
34  {
35    data_type     => "timestamp",
36    default_value => \"current_timestamp",
37    is_nullable   => 1,
38    original      => { default_value => \"now()" },
39  },
40  "ssid",
41  { data_type => "text", is_nullable => 0, default_value => '' },
42);
43__PACKAGE__->set_primary_key("mac", "ssid");
44
45
46
47=head1 RELATIONSHIPS
48
49=head2 oui
50
51Returns the C<oui> table entry matching this Node. You can then join on this
52relation and retrieve the Company name from the related table.
53
54The JOIN is of type LEFT, in case the OUI table has not been populated.
55
56=cut
57
58__PACKAGE__->belongs_to( oui => 'App::Netdisco::DB::Result::Oui',
59    sub {
60        my $args = shift;
61        return {
62            "$args->{foreign_alias}.oui" =>
63              { '=' => \"substring(cast($args->{self_alias}.mac as varchar) for 8)" }
64        };
65    },
66    { join_type => 'LEFT' }
67);
68
69=head2 node
70
71Returns the C<node> table entry matching this wireless entry.
72
73The JOIN is of type LEFT, in case the C<node> is no longer present in the
74database but the relation is being used in C<search()>.
75
76=cut
77
78__PACKAGE__->belongs_to( node => 'App::Netdisco::DB::Result::Node',
79                       { 'foreign.mac' => 'self.mac' },
80                       { join_type => 'LEFT' } );
81
82=head1 ADDITIONAL COLUMNS
83
84=head2 net_mac
85
86Returns the C<mac> column instantiated into a L<NetAddr::MAC> object.
87
88=cut
89
90sub net_mac { return NetAddr::MAC->new(mac => ((shift)->mac || '')) }
91
921;
93