change sub attr to be simple rel to improve efficiency of joins
This commit is contained in:
@@ -76,24 +76,27 @@ __PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip',
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
__PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan',
|
__PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan',
|
||||||
sub {
|
{
|
||||||
my $args = shift;
|
'foreign.ip' => 'self.ip',
|
||||||
return {
|
'foreign.port' => 'self.port',
|
||||||
"$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
|
},
|
||||||
"$args->{foreign_alias}.port" => { -ident => "$args->{self_alias}.port" },
|
{
|
||||||
-not_bool => "$args->{foreign_alias}.native",
|
where => { -not_bool => 'me.native' },
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
__PACKAGE__->many_to_many( tagged_vlans => 'port_vlans_tagged', 'vlan' );
|
__PACKAGE__->many_to_many( tagged_vlans => 'port_vlans_tagged', 'vlan' );
|
||||||
|
# weirdly I could not get row.tagged.vlans.count to work in TT
|
||||||
|
# so gave up and wrote this instead.
|
||||||
|
sub tagged_vlans_count {
|
||||||
|
return (shift)->tagged_vlans->count;
|
||||||
|
}
|
||||||
__PACKAGE__->might_have( native_port_vlan => 'Netdisco::DB::Result::DevicePortVlan',
|
__PACKAGE__->might_have( native_port_vlan => 'Netdisco::DB::Result::DevicePortVlan',
|
||||||
sub {
|
{
|
||||||
my $args = shift;
|
'foreign.ip' => 'self.ip',
|
||||||
return {
|
'foreign.port' => 'self.port',
|
||||||
"$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
|
},
|
||||||
"$args->{foreign_alias}.port" => { -ident => "$args->{self_alias}.port" },
|
{
|
||||||
-bool => "$args->{foreign_alias}.native",
|
where => { -bool => 'me.native' },
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
sub native_vlan {
|
sub native_vlan {
|
||||||
|
|||||||
@@ -39,23 +39,21 @@ __PACKAGE__->set_primary_key("ip", "vlan");
|
|||||||
|
|
||||||
__PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip' );
|
__PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip' );
|
||||||
__PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan',
|
__PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan',
|
||||||
sub {
|
{
|
||||||
my $args = shift;
|
'foreign.ip' => 'self.ip',
|
||||||
return {
|
'foreign.vlan' => 'self.vlan',
|
||||||
"$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
|
},
|
||||||
"$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" },
|
{
|
||||||
-not_bool => "$args->{foreign_alias}.native",
|
where => { -not_bool => 'me.native' },
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
__PACKAGE__->has_many( port_vlans_native => 'Netdisco::DB::Result::DevicePortVlan',
|
__PACKAGE__->has_many( port_vlans_native => 'Netdisco::DB::Result::DevicePortVlan',
|
||||||
sub {
|
{
|
||||||
my $args = shift;
|
'foreign.ip' => 'self.ip',
|
||||||
return {
|
'foreign.vlan' => 'self.vlan',
|
||||||
"$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" },
|
},
|
||||||
"$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" },
|
{
|
||||||
-bool => "$args->{foreign_alias}.native",
|
where => { -bool => 'me.native' },
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
__PACKAGE__->many_to_many( tagging_ports => 'port_vlans_tagged', 'port' );
|
__PACKAGE__->many_to_many( tagging_ports => 'port_vlans_tagged', 'port' );
|
||||||
|
|||||||
Reference in New Issue
Block a user