| 1 | use utf8; | ||
| 2 | package Rapi::Blog::DB::Result::PostTag; | ||
| 3 | |||
| 4 | # Created by DBIx::Class::Schema::Loader | ||
| 5 | # DO NOT MODIFY THE FIRST PART OF THIS FILE | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | |||
| 10 | use Moose; | ||
| 11 | use MooseX::NonMoose; | ||
| 12 | use MooseX::MarkAsMethods autoclean => 1; | ||
| 13 | extends 'DBIx::Class::Core'; | ||
| 14 | __PACKAGE__->load_components("InflateColumn::DateTime"); | ||
| 15 | __PACKAGE__->table("post_tag"); | ||
| 16 | __PACKAGE__->add_columns( | ||
| 17 | "id", | ||
| 18 | { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, | ||
| 19 | "post_id", | ||
| 20 | { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, | ||
| 21 | "tag_name", | ||
| 22 | { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 64 }, | ||
| 23 | ); | ||
| 24 | __PACKAGE__->set_primary_key("id"); | ||
| 25 | __PACKAGE__->belongs_to( | ||
| 26 | "post", | ||
| 27 | "Rapi::Blog::DB::Result::Post", | ||
| 28 | { id => "post_id" }, | ||
| 29 | { is_deferrable => 0, on_delete => "CASCADE", on_update => "CASCADE" }, | ||
| 30 | ); | ||
| 31 | __PACKAGE__->belongs_to( | ||
| 32 | "tag_name", | ||
| 33 | "Rapi::Blog::DB::Result::Tag", | ||
| 34 | { name => "tag_name" }, | ||
| 35 | { is_deferrable => 0, on_delete => "RESTRICT", on_update => "RESTRICT" }, | ||
| 36 | ); | ||
| 37 | |||
| 38 | |||
| 39 | # Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-05-26 13:35:23 | ||
| 40 | # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1X1Cff0uOuglwA9boBo+IQ | ||
| 41 | |||
| 42 | use RapidApp::Util ':all'; | ||
| 43 | |||
| 44 | __PACKAGE__->load_components('+Rapi::Blog::DB::Component::SafeResult'); | ||
| 45 | |||
| 46 | sub insert { | ||
| 47 | my $self = shift; | ||
| 48 | my $columns = shift; | ||
| 49 | $self->set_inflated_columns($columns) if $columns; | ||
| 50 | |||
| 51 | my $kw = $self->get_column('tag_name'); | ||
| 52 | |||
| 53 | $self->result_source->schema | ||
| 54 | ->resultset('Tag') | ||
| 55 | ->find_or_create( | ||
| 56 | { name => $kw }, | ||
| 57 | { key => 'primary' } | ||
| 58 | ); | ||
| 59 | |||
| 60 | $self->next::method; | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | |||
| 65 | # You can replace this text with custom code or comments, and it will be preserved on regeneration | ||
| 66 | __PACKAGE__->meta->make_immutable; | ||
| 67 | 1; |