[Catalyst] relationship or user problem

Wijnand Wiersma wijnand at nedbsd.nl
Mon Feb 6 17:33:08 CET 2006


Hi all,

I don't know if it is my lack of knowledge or a real problem but it  
is a problem :-)

I have two tables and they are related to eachother.
One table person:
CREATE TABLE person (
     id serial NOT NULL,
     name character varying(128),
     address character varying(255),
     zip character varying(10),
     town character varying(64),
     country character(2) NOT NULL,
     phone character varying(32),
     email character varying(128),
     homepage character varying(128),
     extra text,
     created timestamp without time zone,
     updated timestamp without time zone,
     "password" character varying(64),
     company integer,
     username character varying(32),
     birthday date DEFAULT '1970-01-01'::date NOT NULL
);

And one table pskills
CREATE TABLE pskills (
	id SERIAL PRIMARY KEY,
	person INT NOT NULL,
	name VARCHAR(32) NOT NULL,
	level INT NOT NULL,
	years INT NOT NULL);

ALTER TABLE ONLY pskills
	    ADD CONSTRAINT personfk FOREIGN KEY (person) REFERENCES person 
(id) MATCH FULL;

As you can see pskills.person references to person.id

In my models I have following lines:
Person.pm
__PACKAGE__->has_many('pskills' => 'bsdjobs::Model::DBIC::Pskills',  
'person');
Pskills.pm
__PACKAGE__->belongs_to(person => bsdjobs::Model::DBIC::Person);

The person table is also the table I authenticate to.
When a person logs in he gets is profile page, a nice overview of his  
settings.
I wish to add a list of his defined skills there too so I have  
following code in my template:
<h4>Your skills</h4>
<a href="/persons/addskill">Add a skill</a>
<ul>
[% FOREACH skill c.user.user.pskills %]
   <li>skill.name</li>
[% END %]
</ul>

When I request this page with a user that has 3 rows in pskills there  
is nothing between the ul's. So it seems c.user.user.pskills is not  
defined.

I thought this would work automatically like this but I guess I am  
wrong.
How can I use this relationship?

Wijnand






More information about the Catalyst mailing list