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/amazon.tt b/Literature/views/amazon.tt new file mode 100644 index 0000000..5a34800 --- /dev/null +++ b/Literature/views/amazon.tt @@ -0,0 +1,18 @@ + + 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 -%] diff --git a/literature.dat b/literature.dat index d71db61..34e2dc0 100644 --- a/literature.dat +++ b/literature.dat @@ -84,6 +84,15 @@ INSERT INTO `production` VALUES (1,'Pride and Prejudice',22,1995,'BBC'),(2,'Prid /*!40000 ALTER TABLE `production` ENABLE KEYS */; UNLOCK TABLES; +-- +-- Dumping data for table `production_product` +-- + +LOCK TABLES `production_product` WRITE; +/*!40000 ALTER TABLE `production_product` DISABLE KEYS */; +/*!40000 ALTER TABLE `production_product` ENABLE KEYS */; +UNLOCK TABLES; + -- -- Dumping data for table `work` -- @@ -93,6 +102,16 @@ LOCK TABLES `work` WRITE; INSERT INTO `work` VALUES (1,'The Pickwick Papers','1836-03-31 00:00:00'),(2,'The Adventures of Oliver Twist','1837-02-28 00:00:00'),(3,'The Life and Adventures of Nicholas Nickleby','1838-04-30 00:00:00'),(4,'The Old Curiosity Shop','1840-04-25 00:00:00'),(5,'Barnaby Rudge','1841-02-13 00:00:00'),(6,'A Christmas Carol','1843-12-19 00:00:00'),(7,'The Chimes','1844-12-01 00:00:00'),(8,'The Cricket on the Hearth','1845-12-20 00:00:00'),(9,'The Battle of Life','1846-12-01 00:00:00'),(10,'The Haunted Man and the Ghost\'s Bargain','1848-12-19 00:00:00'),(11,'The Life and Adventures of Martin Chuzzlewit','1843-01-01 00:00:00'),(12,'Dombey and Son','1846-10-01 00:00:00'),(13,'David Copperfield','1849-05-01 00:00:00'),(14,'Bleak House','1852-03-01 00:00:00'),(15,'Hard Times','1854-04-01 00:00:00'),(16,'Little Dorrit','1855-12-01 00:00:00'),(17,'A Tale of Two Cities','1859-04-30 00:00:00'),(18,'Great Expectations','1860-12-01 00:00:00'),(19,'Our Mutual Friend','1864-05-01 00:00:00'),(20,'The Mystery of Edwin Drood','1870-04-01 00:00:00'),(21,'Sense and Sensibility','1811-01-01 00:00:00'),(22,'Pride and Prejudice','1813-01-28 00:00:00'),(23,'Mansfield Park','1814-07-01 00:00:00'),(24,'Emma','1815-12-01 00:00:00'),(25,'Northanger Abbey','1817-12-01 00:00:00'),(26,'Persuasion','1818-01-01 00:00:00'),(27,'Henry VI Part I',NULL),(28,'Henry VI Part II',NULL),(29,'Henry VI Part III',NULL),(30,'Richard III',NULL),(31,'The Comedy of Errors',NULL),(32,'Titus Andronicus',NULL),(33,'The Taming of the Shrew',NULL),(34,'The Two Gentlemen of Verona',NULL),(35,'Love\'s Labour\'s Lost',NULL),(36,'Romeo and Juliet',NULL),(37,'Richard II',NULL),(38,'A Midsummers Night\'s Dream',NULL),(39,'King John',NULL),(40,'The Merchant of Venice',NULL),(41,'Henry IV Part I',NULL),(42,'Henry IV Part II',NULL),(43,'Henry V',NULL),(44,'Julius Caesar',NULL),(45,'Much Ado About Nothing',NULL),(46,'As You Like It',NULL),(47,'The Merry Wives of Windsor',NULL),(48,'Hamlet',NULL),(49,'Twelfth Night',NULL),(50,'Troilus and Cressida',NULL),(51,'All\'s Well That Ends Well',NULL),(52,'Othello',NULL),(53,'King Lear',NULL),(54,'Macbeth',NULL),(55,'Measure for Measure',NULL),(56,'Antony and Cleopatra',NULL),(57,'Coriolanus',NULL),(58,'Timon of Athens',NULL),(59,'Pericles Prince of Tyre',NULL),(60,'Cymberline',NULL),(61,'The Winter\'s Tales',NULL),(62,'The Tempest',NULL); /*!40000 ALTER TABLE `work` ENABLE KEYS */; UNLOCK TABLES; + +-- +-- Dumping data for table `work_product` +-- + +LOCK TABLES `work_product` WRITE; +/*!40000 ALTER TABLE `work_product` DISABLE KEYS */; +INSERT INTO `work_product` VALUES (1,22,'1853260002'),(2,22,'1847624812'),(3,22,'0192789864'),(4,22,'B00CF69XOG'),(5,22,'B008476HBM'),(6,22,'190463351X'); +/*!40000 ALTER TABLE `work_product` ENABLE KEYS */; +UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -102,4 +121,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2015-10-01 20:50:39 +-- Dump completed on 2015-10-01 21:43:23 diff --git a/literature.sql b/literature.sql index 4b50d2b..c600584 100644 --- a/literature.sql +++ b/literature.sql @@ -138,6 +138,23 @@ CREATE TABLE `production` ( ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `production_product` +-- + +DROP TABLE IF EXISTS `production_product`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `production_product` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `production_id` int(11) NOT NULL, + `asin` char(20) NOT NULL, + PRIMARY KEY (`id`), + KEY `production_id` (`production_id`), + CONSTRAINT `production_product_ibfk_1` FOREIGN KEY (`production_id`) REFERENCES `production` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `work` -- @@ -153,6 +170,23 @@ CREATE TABLE `work` ( KEY `title` (`title`) ) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `work_product` +-- + +DROP TABLE IF EXISTS `work_product`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `work_product` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `work_id` int(11) NOT NULL, + `asin` char(20) NOT NULL, + PRIMARY KEY (`id`), + KEY `work_id` (`work_id`), + CONSTRAINT `work_product_ibfk_1` FOREIGN KEY (`work_id`) REFERENCES `work` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; @@ -163,4 +197,4 @@ CREATE TABLE `work` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2015-10-01 20:50:07 +-- Dump completed on 2015-10-01 21:43:34