From fac4678040140b5dbfbf4a197e3d0fef2910f47b Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Tue, 8 Oct 2013 15:55:39 +0200 Subject: [PATCH] MT#4025 Link contract and sound set tables. This is needed to let customers handle their own sound sets for pbx accounts. --- lib/NGCP/Schema/Result/contracts.pm | 7 +++++++ lib/NGCP/Schema/Result/voip_sound_sets.pm | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/NGCP/Schema/Result/contracts.pm b/lib/NGCP/Schema/Result/contracts.pm index 955ea922..88cbf0fb 100644 --- a/lib/NGCP/Schema/Result/contracts.pm +++ b/lib/NGCP/Schema/Result/contracts.pm @@ -180,6 +180,13 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "voip_sound_sets", + "NGCP::Schema::Result::voip_sound_sets", + { "foreign.contract_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub TO_JSON { my ($self) = @_; return { diff --git a/lib/NGCP/Schema/Result/voip_sound_sets.pm b/lib/NGCP/Schema/Result/voip_sound_sets.pm index 21f9a796..28d8b24e 100644 --- a/lib/NGCP/Schema/Result/voip_sound_sets.pm +++ b/lib/NGCP/Schema/Result/voip_sound_sets.pm @@ -28,6 +28,12 @@ __PACKAGE__->add_columns( is_foreign_key => 1, is_nullable => 0, }, + "contract_id", + { + data_type => "integer", + extra => { unsigned => 1 }, + is_nullable => 1, + }, "name", { data_type => "varchar", is_nullable => 1, size => 256 }, "description", @@ -44,12 +50,21 @@ __PACKAGE__->has_many( { "foreign.set_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); + __PACKAGE__->belongs_to( "reseller", "NGCP::Schema::Result::resellers", { id => "reseller_id" }, { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); + +__PACKAGE__->belongs_to( + "contract", + "NGCP::Schema::Result::contracts", + { 'foreign.id' => 'self.contract_id' }, + { 'join_type' => 'left', is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + sub TO_JSON { my ($self) = @_; return {