Re: object cache problem

[prev] [thread] [next] [Date index for 2005/05/24]

From: Perrin Harkins
Subject: Re: object cache problem
Date: 15:00 on 24 May 2005
On Tue, 2005-05-24 at 03:38 -0700, Ask Bj=C3=B8rn Hansen wrote:
> package Music::Artist;
> use base qw(Music::DBI);
> __PACKAGE__->table('artists');
> __PACKAGE__->columns(Essential =3D> qw/id name primary_cd/);
> __PACKAGE__->has_a(primary_cd =3D> 'Music::CD');
> __PACKAGE__->has_many(cds =3D> 'Music::CD');
>=20
>=20
> package Music::CD;
> use base qw(Music::DBI);
> __PACKAGE__->table('cds');
> __PACKAGE__->columns(Essential =3D> qw/id title artist /);
> __PACKAGE__->has_a(artist =3D> 'Music::Artist');
>=20
> using $artist->primary_cd->title causes the problem.

It probably won't if you take "artist" out of Essential in Music::CD,
but only if you don't call artist() on it.

You could fix this by making your own Music::CD->artist() accessor that
doesn't cache the result (I'm not talking about the object index --
has_a actually cache the result for the lifetime of the "parent"
object), or by changing your schema to avoid the two-way link, maybe
replacing primary_cd with a flag column in your cds table and writing a
custom SQL query for it.

- Perrin

object cache problem
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 10:38 on 24 May 2005

Re: object cache problem
Perrin Harkins 15:00 on 24 May 2005

Generated at 15:51 on 25 May 2005 by mariachi v0.52