[Catalyst] Catalyst DBIX stash, getting at the data

Tadhg tadhg.daley at gmail.com
Mon Oct 15 19:28:11 GMT 2012


Hi,

I'm developing my first Catalyst application, Windows, MySQL, DBIx and
Template Toolkit. As part of this I've overcome various problems and now
have a working app, but I'm having recurring difficulties understanding the
relationship between DBIx, Catalyst and TT.

What I want is simply to select a row from a table by its ID (no problem),
assign the 'name' field/column to a variable, and finally store it as a
parameter in the session.
For this I hoping you'll answer 2 questions:
        1. Simply how to do this, or point me to an existing example (I've
looked a few times, but maybe I'm looking for the wrong thing)?
        2. How should I be doing this, as I'm new to Catalyst DBIx and TT.
There is a certain amount of 'get it working' as opposed to how it should
work, but I guess that's what catalyst is for?

Catalyst Controller Code:
sub Project :Local {
    my ($self, $c, $project_id) =3D @_;

        $c->stash(projects =3D>
[$c->model('DB::Project')->find({'Project_id', $project_id })]);
        die "App $project_id not found!" if !$c->stash->{projects};     #
This all works fine

        # This is a guess and doesn't work ;-)
        $c->session{Project} =3D> $c->stash->{projects}->project_name;
        # Where project_name is an accessor in the DBIx result set.
}

>From DB::Project
__PACKAGE__->add_columns(
  "project_id",
  { data_type =3D> "integer", is_auto_increment =3D> 1, is_nullable =3D> 0 =
},
  "project_name",
  { data_type =3D> "varchar", is_nullable =3D> 0, size =3D> 255 },

Sample DB Table:
CREATE  project (
  `Project_id` INT AUTO_INCREMENT ,
  `Project_Name` VARCHAR(255) NOT NULL ,
  `FK_Programme` INT NOT NULL ,
  `Project_Desc` VARCHAR(255) NULL ,
)

Regards,
Tadhg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20121015/bc046=
bb7/attachment.htm


More information about the Catalyst mailing list