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

Dave Howorth dhoworth@mrc-lmb.cam.ac.uk
Mon, 25 Oct 2004 11:25:44 +0100


> In other words, there are two tables (engineer, project), and two tabs 
> at the top of the above webpage, one for each. Each URL points to 
> http://localhost/projectsengineer/list/ or 
> http://localhost/projectsproject/list/ respectively. There should be 
> another '/' in the middle of those URLs.

There was a missing slash in the link macro in the 'macros' template. I 
guess the answer now is to upgrade to Maypole 2 rather than fix the 1.7 
template.


> CDBI::Loader::Relationship isn't doing the right thing when I request a 
> has_many relationship. has_a works just fine. I'm trying to say that any 
> project can have one or more engineers working on it.

You're saying "a project has engineers". When you do that, you're 
implying that the engineer table has a project field through which the 
linkage is made. But your schema doesn't have that structure. Your 
schema would support the relationship "an engineer has projects".

Cheers, Dave

> 
> I've been tracing through this in the debugger all day and don't see why 
> this shouldn't work (tests trimmed for brevity):
> 
>   use Test::More tests => 9;
>   use Class::DBI::Loader;
>   use Class::DBI::Loader::Relationship;
> 
>   ok $loader = Class::DBI::Loader->new(
>         dsn => "dbi:mysql:projects",
>         user => 'projects',
>         password => 'projects',
>   ), 'new() CDBI::Loader::Relationship';
> 
>   ok $loader->relationship( 'a project has an engineer'  ),
>     'a project has an engineer';
> 
>   can_ok Engineer => 'eng_id';
>   can_ok Engineer => 'first_name';
>   can_ok Engineer => 'last_name';
>   can_ok Project  => 'project_id';
>   can_ok Project  => 'name';
>   can_ok Project  => 'description';
> 
>   # XXX This fails:
>   ok $loader->relationship( 'a project has engineers' ),
>     'a project has engineers';
> 
> __END__
> 
> The last test fails with error message:
> "has_a needs a valid column at 
> /usr/local/lib/site_perl/5.8.1/Class/DBI/Relationship/HasA.pm line 12"
> 
> Note: I realize that it's a little sloppy building both a has_a 
> relationship as well as a has_many in the same file. Separating the 
> calls into separate files yields the same behavior so it's a wash.
> 
> I'm working with:
> 
> CREATE TABLE engineer (
>   eng_id int(11) NOT NULL auto_increment,
>   first_name varchar(128) NOT NULL default '',
>   last_name varchar(128) NOT NULL default '',
>   PRIMARY KEY  (eng_id)
> ) TYPE=InnoDB;
> 
> CREATE TABLE project (
>   project_id int(11) NOT NULL auto_increment,
>   name varchar(128) NOT NULL default '',
>   cfr mediumint(9) default NULL,
>   description text,
>   start_date date NOT NULL default '0000-00-00',
>   end_date date default NULL,
>   status text,
>   status_date date default NULL,
>   engineer int(11) default NULL,
>   is_complete tinyint(1) default NULL,
>   PRIMARY KEY  (project_id)
> ) TYPE=InnoDB;
> 
> Thank-you all again, very much,
> Joshua
> 
> 
> _______________________________________________
> maypole mailing list
> maypole@lists.netthink.co.uk
> http://lists.netthink.co.uk/listinfo/maypole
> 


-- 
Dave Howorth
MRC Centre for Protein Engineering
Hills Road, Cambridge, CB2 2QH
01223 252960