| 1 | use utf8; | ||
| 2 | package Rapi::Blog::DB::Result::Category; | ||
| 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("category"); | ||
| 16 | __PACKAGE__->add_columns( | ||
| 17 | "name", | ||
| 18 | { data_type => "varchar", is_nullable => 0, size => 64 }, | ||
| 19 | "description", | ||
| 20 | { | ||
| 21 | data_type => "varchar", | ||
| 22 | default_value => \"null", | ||
| 23 | is_nullable => 1, | ||
| 24 | size => 1024, | ||
| 25 | }, | ||
| 26 | ); | ||
| 27 | __PACKAGE__->set_primary_key("name"); | ||
| 28 | __PACKAGE__->has_many( | ||
| 29 | "post_categories", | ||
| 30 | "Rapi::Blog::DB::Result::PostCategory", | ||
| 31 | { "foreign.category_name" => "self.name" }, | ||
| 32 | { cascade_copy => 0, cascade_delete => 0 }, | ||
| 33 | ); | ||
| 34 | |||
| 35 | |||
| 36 | # Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-08-20 20:36:08 | ||
| 37 | # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9R1QEXzoBCbh4hJhMmAztw | ||
| 38 | |||
| 39 | use RapidApp::Util ':all'; | ||
| 40 | use Rapi::Blog::Util; | ||
| 41 | |||
| 42 | __PACKAGE__->load_components('+Rapi::Blog::DB::Component::SafeResult'); | ||
| 43 | |||
| 44 | sub insert { | ||
| 45 | my $self = shift; | ||
| 46 | my $columns = shift; | ||
| 47 | |||
| 48 | if(my $User = Rapi::Blog::Util->get_User) { | ||
| 49 | die usererr "Create Category: PERMISSION DENIED" if ($User->id && !$User->admin); | ||
| 50 | } | ||
| 51 | |||
| 52 | $self->set_inflated_columns($columns) if $columns; | ||
| 53 | |||
| 54 | $self->next::method | ||
| 55 | } | ||
| 56 | |||
| 57 | sub update { | ||
| 58 | my $self = shift; | ||
| 59 | my $columns = shift; | ||
| 60 | |||
| 61 | if(my $User = Rapi::Blog::Util->get_User) { | ||
| 62 | die usererr "Update Category: PERMISSION DENIED" if ($User->id && !$User->admin); | ||
| 63 | } | ||
| 64 | |||
| 65 | $self->set_inflated_columns($columns) if $columns; | ||
| 66 | |||
| 67 | $self->next::method | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 | sub delete { | ||
| 72 | my $self = shift; | ||
| 73 | |||
| 74 | if(my $User = Rapi::Blog::Util->get_User) { | ||
| 75 | die usererr "Delete Category: PERMISSION DENIED" if ($User->id && !$User->admin); | ||
| 76 | } | ||
| 77 | |||
| 78 | $self->next::method(@_) | ||
| 79 | } | ||
| 80 | |||
| 81 | |||
| 82 | sub posts_count { | ||
| 83 | my $self = shift; | ||
| 84 | # In case the ResultSet has pre-loaded this value, don't do another query: | ||
| 85 | my $preload = try{$self->get_column('posts_count')}; | ||
| 86 | defined $preload ? $preload : $self->post_categories->count | ||
| 87 | } | ||
| 88 | |||
| 89 | # You can replace this text with custom code or comments, and it will be preserved on regeneration | ||
| 90 | __PACKAGE__->meta->make_immutable; | ||
| 91 | 1; |