Re: conflicting advice about has_a and primary keys

[prev] [thread] [next] [Date index for 2004/05/18]

From: Charles Bailey
Subject: Re: conflicting advice about has_a and primary keys
Date: 20:20 on 18 May 2004
--On Tuesday, May 18, 2004 2:04 PM -0400 Perrin Harkins <perrin@xxxx.xxx> 
wrote:

> The CDBI docs contain this piece of advice in the has_a() section:
>
> "*NOTE* You should not attempt to make your primary key column inflate
> using has_a() as bad things will happen. If you have two tables which
> share a primary key, consider using might_have() instead."
>
> A little further down in the many-to-many section, it breaks this rule.
>
> "First of all we'll set up our Role class:
>
>         Role->table('role');
>         Role->columns(Primary => qw/film actor/);
>         Role->has_a(film => 'Film');
>         Role->has_a(actor => 'Actor');
>
> We have a multi-column primary key, with each column pointing to another
> class."
>
> Which of these is correct?  Or is it just that using has_a() on your
> primary key fails if you specify an inflate() method?

The problem is that the PK value will be deflated whenever the object is 
updated, and will not be reinflated automagically, since it's not deleted. 
The test suite never checks keys after an update, so it doesn't complain.

The patch I posted just after 0.96 came out adds tests that demonstrate the 
problem, and fixes it; with the patch, you may use default or custom 
inflators for PK columns.


--
Regards,
Charles Bailey  < bailey _at_ newman _dot_ upenn _dot_ edu >
Newman Center at the University of Pennsylvania

conflicting advice about has_a and primary keys
Perrin Harkins 18:04 on 18 May 2004

Re: conflicting advice about has_a and primary keys
Vince Veselosky 18:58 on 18 May 2004

Re: conflicting advice about has_a and primary keys
Charles Bailey 20:20 on 18 May 2004

Generated at 11:35 on 01 Dec 2004 by mariachi v0.52