From 275559bd32b24a2a65c6730ff8679f99160ad828 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Thu, 1 Oct 2015 22:00:00 +0100 Subject: [PATCH] Added product tables. --- .../Literature/Schema/Result/Production.pm | 19 +++- .../Schema/Result/ProductionProduct.pm | 106 ++++++++++++++++++ .../lib/Literature/Schema/Result/Work.pm | 26 ++++- .../Literature/Schema/Result/WorkProduct.pm | 106 ++++++++++++++++++ Literature/views/work.tt | 22 +++- 5 files changed, 274 insertions(+), 5 deletions(-) create mode 100644 Literature/lib/Literature/Schema/Result/ProductionProduct.pm create mode 100644 Literature/lib/Literature/Schema/Result/WorkProduct.pm diff --git a/Literature/lib/Literature/Schema/Result/Production.pm b/Literature/lib/Literature/Schema/Result/Production.pm index c1b3693..25946dc 100644 --- a/Literature/lib/Literature/Schema/Result/Production.pm +++ b/Literature/lib/Literature/Schema/Result/Production.pm @@ -111,6 +111,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 production_products + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "production_products", + "Literature::Schema::Result::ProductionProduct", + { "foreign.production_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 work Type: belongs_to @@ -127,8 +142,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 20:37:37 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Pbb3FP5cA/ANMlrxEZkWiw +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 21:43:50 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:VKyKvC7VRvcrLrcmb7NMKA # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/Literature/lib/Literature/Schema/Result/ProductionProduct.pm b/Literature/lib/Literature/Schema/Result/ProductionProduct.pm new file mode 100644 index 0000000..c0fef40 --- /dev/null +++ b/Literature/lib/Literature/Schema/Result/ProductionProduct.pm @@ -0,0 +1,106 @@ +use utf8; +package Literature::Schema::Result::ProductionProduct; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Literature::Schema::Result::ProductionProduct + +=cut + +use strict; +use warnings; + +use Moose; +use MooseX::NonMoose; +use MooseX::MarkAsMethods autoclean => 1; +extends 'DBIx::Class::Core'; + +=head1 COMPONENTS LOADED + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->load_components("InflateColumn::DateTime"); + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("production_product"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 production_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 asin + + data_type: 'char' + is_nullable: 0 + size: 20 + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "production_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "asin", + { data_type => "char", is_nullable => 0, size => 20 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 RELATIONS + +=head2 production + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "production", + "Literature::Schema::Result::Production", + { id => "production_id" }, + { is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 21:43:50 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:vPLXwNMJRQWtSYhJyZgcKg + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +__PACKAGE__->meta->make_immutable; +1; diff --git a/Literature/lib/Literature/Schema/Result/Work.pm b/Literature/lib/Literature/Schema/Result/Work.pm index f510ddb..d80a211 100644 --- a/Literature/lib/Literature/Schema/Result/Work.pm +++ b/Literature/lib/Literature/Schema/Result/Work.pm @@ -130,6 +130,21 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); +=head2 work_products + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "work_products", + "Literature::Schema::Result::WorkProduct", + { "foreign.work_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + =head2 authors Type: many_to_many @@ -155,9 +170,16 @@ __PACKAGE__->many_to_many( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 20:37:37 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:P4SAb/GK/gfabamQ5HGNBA +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 21:43:50 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:iNlGbrhdinEjHcBTc609zg + +sub asins { + my $self = shift; + + return () unless $self->work_products->count; + return map { $_->asin } $self->work_products->all; +} # You can replace this text with custom code or comments, and it will be preserved on regeneration __PACKAGE__->meta->make_immutable; diff --git a/Literature/lib/Literature/Schema/Result/WorkProduct.pm b/Literature/lib/Literature/Schema/Result/WorkProduct.pm new file mode 100644 index 0000000..1a755be --- /dev/null +++ b/Literature/lib/Literature/Schema/Result/WorkProduct.pm @@ -0,0 +1,106 @@ +use utf8; +package Literature::Schema::Result::WorkProduct; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Literature::Schema::Result::WorkProduct + +=cut + +use strict; +use warnings; + +use Moose; +use MooseX::NonMoose; +use MooseX::MarkAsMethods autoclean => 1; +extends 'DBIx::Class::Core'; + +=head1 COMPONENTS LOADED + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->load_components("InflateColumn::DateTime"); + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("work_product"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 work_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 asin + + data_type: 'char' + is_nullable: 0 + size: 20 + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "work_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "asin", + { data_type => "char", is_nullable => 0, size => 20 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 RELATIONS + +=head2 work + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "work", + "Literature::Schema::Result::Work", + { id => "work_id" }, + { is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-10-01 21:43:50 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ejeRY+8ND9weKp9VO8W4bw + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +__PACKAGE__->meta->make_immutable; +1; diff --git a/Literature/views/work.tt b/Literature/views/work.tt index a49d905..23cb355 100644 --- a/Literature/views/work.tt +++ b/Literature/views/work.tt @@ -22,7 +22,27 @@ [% ELSE %]

No productions found

[% END %] +[% IF work.work_products.all.size -%]

Buy the Book

+ + [% FOR p IN work.work_products %] -[% END %] +[% END -%] +[% END -%]