Created
August 8, 2010 20:02
-
-
Save dhoss/514467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## some names changed | |
Caught exception in MyApp::Controller::Dashboard->index "Can't locate object method "overall_ranking_num" via package "MyApp::Model::DB::Rankings" at /...../lib/MyApp/Controller/Dashboard.pm line 132." | |
## controller code: | |
## $channel isa MyApp::Schema::Result::DB::Profiles | |
$channel->ranking->overall_ranking_num( $channel, $stat, 6 ); | |
package MyApp::Schema::DB::ResultSet::Rankings; | |
use strict; | |
use warnings; | |
use base 'DBIx::Class::ResultSet'; | |
use Data::Dumper; | |
sub overall_ranking_num { | |
my ($self, $profile, $stat, $num_neighbors) = @_; | |
my @rs = $profile->profile_stats->search( {}, { order_by => $stat, rows => $num_neighbors }); | |
my @results; | |
my $rank = 1; | |
for my $row ( @rs ) { | |
push @results, [$row->id, $rank++]; | |
} | |
warn "Results: " . Dumper \@results; | |
return \@results; | |
} | |
1; | |
package MyApp::Schema::DB::Result::Rankings; | |
use base qw/ MyApp::Schema::DB::Result::Profiles /; | |
__PACKAGE__->table('profiles'); | |
__PACKAGE__->resultset_class('MyApp::Schema::DB::ResultSet::Rankings'); | |
__PACKAGE__->belongs_to('user' => 'MyApp::Schema::DB::Result::Profiles', | |
{ | |
'foreign.id' => 'self.id' | |
} | |
); | |
1; | |
in ::Profiles: | |
__PACKAGE__->has_one("ranking" => "MyApp::Schema::DB::Result::Rankings", | |
{ "foreign.id" => "self.id" } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment