tobiash has asked for the wisdom of the Perl Monks concerning the following question:
package MyApp::Location; use base qw/DBIx::Class/; ... __PACKAGE__->add_columns( ... location => { data_type => 'point', }, ); ... # custom result set my $source = __PACKAGE__->result_source_instance(); my $new_source = $source->new( $source ); $new_source->source_name( 'ClosestUsers' ); $new_source->name( \qq{ ( SELECT c.*, GLength(LineStringFromWKB( LineString(AsBinary(c.location), AsBinary(?)))) AS distance FROM loc c ORDER by distance asc LIMIT ?) }); MyApp->register_source( 'ClosestUsers' => $new_source ); ...
my $closeBy = [ $c->model('MyApp')->resultset('ClosestUsers' ) ->search( {}, { bind => [ $somelocation, $numberOfUsers] } ) ];
I want to get rid of that outer select and be able to have the "distance" in my ResultSet.SELECT me.id_checkin, me.user_id, me.modified, me.location, me.accuracy FROM ( SELECT c.*, GLength(LineStringFromWKB( LineString(AsBinary(c.location),AsBinary(?)))) AS distance FROM loc c ORDER by distance asc LIMIT ?)
|
|---|