[Maypole] Error: "has_a needs a valid column"

Dave Howorth dhoworth@mrc-lmb.cam.ac.uk
Fri, 22 Oct 2004 11:54:09 +0100


Sebastian Riedel wrote:
> Am Donnerstag, den 21.10.2004, 18:33 -0700 schrieb Joshua Keroes:
> 
>>Can't get some simple code to work. I've searched for this error 
>>through the Maypole archives, in both Wikis, on google; nothing. I'd 
>>love some help.
>>
>>=== The problem ===

There's more than one problem! Sebastian got most of them, but he's 
missed one I think.

>>(pulled from apache's log and reformatted for legibility)
>>
>>[Thu Oct 21 17:08:09 2004] [error]
>>	has_a needs a valid column at 
>>/usr/local/lib/site_perl/5.8.1/Class/DBI/Relationship/HasA.pm line 12

This is the first problem and is the one Sebastian missed.

>>	Compilation failed in require at (eval 9) line 3.
>>	Use of uninitialized value in subroutine entry at 
>>/usr/local/lib/site_perl/5.8.1/Maypole.pm line 99.
>>	file error - projects: not found at 
>>/usr/local/lib/site_perl/5.8.1/Maypole/View/Base.pm line 68.

This is the second error - the class names.

>>[Thu Oct 21 18:05:32 2004] [error]
>>	[client 127.0.0.1] File does not exist: /usr/local/apache/www/projects

This is a third error - the template location.

>>=== The basics ===
>>
>>OSX machine running mysql-12.22 (fink), perl-5.8.1 (src), Apache/1.3.31 
>>+ mod_perl/1.29 (src)
>>
>>Class::DBI, Class::DBI::Loader::mysql, Class::DBI::mysql, DBD::mysql, 
>>TT2, and the rest of the Maypole framework installed (or at least I'm 
>>pretty sure I have it all in there).
>>
>>
>>=== MySQL setup  ===
>>
>>Both of these are in database "projects".
>>
>>CREATE TABLE projects (
>>         project_id      INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
>>         name            VARCHAR(128) NOT NULL,
>>         cfr             MEDIUMINT,
>>         description     TEXT,
>>         start_date      DATE NOT NULL,
>>         end_date        DATE,
>>         status          TEXT,
>>         status_date     DATE,
>>         eng_id          INT REFERENCES engineers (eng_id),

This is the source of the relationship problem, I believe. The column 
has to be called the same as the name of the other table.

>>         is_complete     TINYINT(1)
>>) TYPE=InnoDb;
>>
>>CREATE TABLE engineers (
>>         eng_id  INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
>>         fname   VARCHAR(128) NOT NULL,
>>         lname   VARCHAR(128) NOT NULL
>>) TYPE=InnoDb;
> 
> 
> Rename tables to "project" and "engineer".

This is also necessary to get grammatical English on your web pages, 
using Maypole's current name translation scheme.

>>These are accessible by user "projects"/password "projects". I have 
>>confirmed this on the command-line.
>>
>>
>>=== Perl setup ===
>>
>>package Maypole::Projects;
>>
>>our $VERSION = '0.01';
>>
>>use base 'Apache::MVC';
>>use Class::DBI::Loader::Relationship;
>>
>>__PACKAGE__->setup( "dbi:mysql:projects", "projects", "projects" );
>>__PACKAGE__->config->{uri_base} = "http://localhost/projects/";
> 
> 
> you should also set {template_root}, not really needed if your Apache is
> configured right, but it's safer.
> 
> 
>>__PACKAGE__->config->{rows_per_page} = 20;
>>__PACKAGE__->config->{loader}->relationship($_) for (
>>         "a  project has engineers",
>>);
>>
>>Maypole::Projects::projects->untaint_columns(
>>         printable => [qw/name description status/],
>>         date => [qw/start_date end_date status_date/],
>>         int => [qw/project_id cfr eng_id is_complete/],
>>);
> 
> Class names are CamelCase, so use "Maypole::Projects::Project".

This solves the second error.

>>Maypole::Projects::engineers->untaint_columns(
>>         printable => [qw/fname lname/],
>>         int => [qw/eng_id/],
>>);
> 
> 
> "Maypole::Projects::Engineer".
> 
> 
>>1;
>>
>>
>>=== Apache setup ===
>>
>>Nothing fancy, just added this to the bottom of httpd.conf:
>>
>><Location /projects/>
>>   SetHandler perl-script
>>   PerlHandler Maypole::Projects
>></Location>
>>
>>
>>=== WHISKEY TANGO FOXTROT AMIGOS ===
>>
>>Maybe my use of setup() is wonky. I haven't seen any examples that also 
>>pass the username and password to mysql via setup() although Simon 
>>mentioned in a changelog that this would be ok. If my use of setup() is 
>>wonky, then perhaps CDBI::Loader::Relationship or a superclass is 
>>failing to log in and/or properly use the projects database.
>>
>>I haven't installed any templates. I was expecting that some default 
>>templates would automatically be used.
> 
> copy templates to the specified {template_root}.

This is necessary to fix the last error in your log.

Cheers, Dave