...
##
####
sub _sort_column {
my $key = shift;
my $array_ref = [];
if( $key eq 'location' ) {
# location is a pseudo-column,
# containing these columns:
$array_ref = [
'astro.galaxy',
'astro.region',
'astro.system',
'astro.astro',
];
}
else {
$array_ref = [ $key ];
}
return $array_ref;
}
####
my $sort_key = $query->param('sortCol') ||
$session->param('sortCol') ||
'location';
$bases_rs = $schema->resultset('Bases')->search(
{
profile_id => $profile->id,
},
{
join => {
'astro' => 'astrotype',
'astro' => 'terrain',
},
prefetch => {
'astro' => 'astrotype',
'astro' => 'terrain',
},
order_by => _sort_column($sort_key),
} ,
);
####
[% FOREACH base IN bases %]
[% IF base.astro %]
[% base.astro.galaxy %]:[% base.astro.region %]:
[% base.astro.system %]:[% base.astro.astro %]
[% base.astro.astrotype.name %]
[% base.astro.terrain.name %]
... lots of other columns removed for brevity
[% END %]
[% END %]
####
package My::Namespace::DB::Bases;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("bases");
__PACKAGE__->add_columns(
"id", { data_type => "BIGINT",
default_value => undef,
is_nullable => 0,
size => 20 },
"astro_id", { data_type => "BIGINT",
default_value => undef,
is_nullable => 0,
size => 20 },
"profile_id", { data_type => "BIGINT",
default_value => undef,
is_nullable => 0,
size => 20 },
... lots of other columns removed for brevity ...
"last_update", { data_type => "TIMESTAMP",
default_value => "CURRENT_TIMESTAMP",
is_nullable => 0,
size => 14, },
);
__PACKAGE__->set_primary_key("id");
# Created by DBIx::Class::Schema::Loader v0.04003 @ 2008-01-26 00:53:23
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:RlHYEvMg3JniB7RL4miPvA
__PACKAGE__->belongs_to(
profile => 'My::Namespace::DB::Profiles',
{ 'foreign.id' => 'self.profile_id' },
);
__PACKAGE__->belongs_to(
astro => 'My::Namespace::DB::Astros',
{ 'foreign.id' => 'self.astro_id' },
{ cascade_delete => 0 },
);
1;
####
package My::Namespace::DB::Astros;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("astros");
__PACKAGE__->add_columns(
"id", { data_type => "BIGINT",
default_value => undef,
is_nullable => 0,
size => 20 },
"galaxy", { data_type => "CHAR",
default_value => "",
is_nullable => 0,
size => 3 },
"region", { data_type => "TINYINT",
default_value => "",
is_nullable => 0,
size => 3 },
"system", { data_type => "TINYINT",
default_value => "",
is_nullable => 0,
size => 3 },
"astro", { data_type => "TINYINT",
default_value => "",
is_nullable => 0,
size => 3 },
"astro_type_id", { data_type => "TINYINT",
default_value => "",
is_nullable => 0,
size => 3 },
"astro_terrain_id", { data_type => "TINYINT",
default_value => "",
is_nullable => 0,
size => 3 },
... lots of other columns removed for brevity ...
"last_update", { data_type => "TIMESTAMP",
default_value => "CURRENT_TIMESTAMP",
is_nullable => 0,
size => 14,
},
);
__PACKAGE__->set_primary_key("id");
# Created by DBIx::Class::Schema::Loader v0.04003 @ 2008-01-26 00:53:23
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L2UqQerufeVtYyq2WeydTQ
__PACKAGE__->has_many(
bases => 'My::Namespace::DB::Bases',
{ 'foreign.astro_id' => 'self.id' },
{ cascade_delete => 0 }
);
__PACKAGE__->has_one(
terrain => 'My::Namespace::DB::AstroTerrains',
{ 'foreign.id' => 'self.astro_terrain_id' },
{ cascade_delete => 0 }
);
__PACKAGE__->has_one(
astrotype => 'My::Namespace::DB::AstroTypes',
{ 'foreign.id' => 'self.astro_type_id' },
{ cascade_delete => 0 }
);
1;
####
package My::Namespace::DB::AstroTypes;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("astro_types");
__PACKAGE__->add_columns(
"id", { data_type => "TINYINT",
default_value => undef,
is_nullable => 0,
size => 3 },
"name", { data_type => "VARCHAR",
default_value => "",
is_nullable => 0,
size => 20 },
"last_update", { data_type => "TIMESTAMP",
default_value => "CURRENT_TIMESTAMP",
is_nullable => 0,
size => 14,
},
);
__PACKAGE__->set_primary_key("id");
# Created by DBIx::Class::Schema::Loader v0.04003 @ 2008-01-26 00:53:23
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yoqPb2NOrr9JVquXfnYsog
__PACKAGE__->has_many(
astros => 'My::Namespace::DB::Astros',
{ 'foreign.astro_type_id' => 'self.id' },
{ cascade_delete => 0 },
);
1;
####
package My::Namespace::DB::AstroTerrains;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("astro_terrains");
__PACKAGE__->add_columns(
"id", { data_type => "TINYINT",
default_value => undef,
is_nullable => 0,
size => 3 },
"name", { data_type => "VARCHAR",
default_value => "",
is_nullable => 0,
size => 20 },
... lots of other columns removed for brevity ...
"last_update", { data_type => "TIMESTAMP",
default_value => "CURRENT_TIMESTAMP",
is_nullable => 0,
size => 14, },
);
__PACKAGE__->set_primary_key("id");
# Created by DBIx::Class::Schema::Loader v0.04003 @ 2008-01-26 00:53:23
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:etM2yf14f59YAtaOo8ltSg
__PACKAGE__->has_many(
astros => 'My::Namespace::DB::Astros',
{ 'foreign.astro_terrain_id' => 'self.id' },
{ cascade_delete => 0 },
);
1;