diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-12-14 12:11:13 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-12-15 00:11:06 +0000 |
commit | ff06783c6dc50321100a54b4d4a624fde2212689 (patch) | |
tree | 38d7f914f841a6ba8ea3225bae3cacbabc80dbf9 /perllib/FixMyStreet/DB/Result/User.pm | |
parent | bb356c880412db8bad655e081ad6d68f25ae3ff7 (diff) |
Make from_body a foreign key.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/User.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 997577b69..481b654c9 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -27,7 +27,7 @@ __PACKAGE__->add_columns( "password", { data_type => "text", default_value => "", is_nullable => 0 }, "from_body", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "flagged", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "title", @@ -53,6 +53,17 @@ __PACKAGE__->has_many( { "foreign.user_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->belongs_to( + "from_body", + "FixMyStreet::DB::Result::Body", + { id => "from_body" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); __PACKAGE__->has_many( "problems", "FixMyStreet::DB::Result::Problem", @@ -61,8 +72,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-12 13:06:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L6gtjOQeVkebGUIHJcHuUA +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aw374WQraL5ysOvUmUIU3w __PACKAGE__->add_columns( "password" => { @@ -146,20 +157,8 @@ sub alert_for_problem { sub body { my $self = shift; - return '' unless $self->from_body; - - my $key = 'body_name:' . $self->from_body; - my $result = Memcached::get($key); - - ### TODO: Add a 'name' column to body which is used instead of calling mapit - unless ($result) { - my $area_info = mySociety::MaPit::call('area', $self->from_body); - $result = $area_info->{name}; - Memcached::set($key, $result, 86400); - } - - return $result; + return $self->from_body->name; } =head2 belongs_to_body @@ -176,7 +175,7 @@ sub belongs_to_body { my %bodies = map { $_ => 1 } split ',', $bodies; - return 1 if $self->from_body && $bodies{ $self->from_body }; + return 1 if $self->from_body && $bodies{ $self->from_body->id }; return 0; } |