Re: create bug

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

From: Perrin Harkins
Subject: Re: create bug
Date: 15:53 on 18 May 2005
On Wed, 2005-05-18 at 16:49 +0200, Hartmaier Alexander wrote:
> What I'm doing is a ->create followed by a method call on a deflated column
> which returns another object.
> The created object is dropped according to the docs after creation to
> prevent changes by other processes etc. to be overwritten.
> It seems that the object is only reloaded if a column is accessed in a
> 'scalar way' and not if it has to be deflated...
> 
> When using the Music::DBI example it would by something like this:
> 
> my $obj_cd = Music::CD->create ({cdid => 1, artist => 1,  title =>
> 'October', year => 1980});
> 
> $obj_cd->artist->sub; # sub would be the name for the custom sub defined for
> the class Music::Artist.
> 
> Is that enough example?

Combined with your previous posts showing the class definition and the
method giving you trouble, it is.  The problem is a result of a
Class::DBI limitation (or bug if you prefer), but it's documented: you
are defining a has_a() relationship on a column that is part of your
primary key.

There are two workarounds I've used for this.  The first is to drop the
object and reload it.  Make sure you undef the object or remove it from
the live objects index.

The other fix is to make your own simple has_a().  This is usually what
I do.  For example:

sub device {
    my $self = shift; 
    return DeviceClass->retrieve($self->_device_fk_accessor());
}

See http://wiki.class-dbi.com/index.cgi?OverridingAutogeneratedAccessors
for info on the accessor I used there.

- Perrin

(message missing)

create bug
Hartmaier Alexander 14:38 on 13 May 2005

Re: create bug
Tony Bowden 19:18 on 13 May 2005

create bug
Hartmaier Alexander 09:56 on 17 May 2005

Re: create bug
Simon Wilcox 10:05 on 17 May 2005

create bug
Hartmaier Alexander 10:49 on 17 May 2005

Re: create bug
Simon Wilcox 11:12 on 17 May 2005

create bug
Hartmaier Alexander 11:15 on 17 May 2005

Re: create bug
Simon Wilcox 13:01 on 17 May 2005

create bug
Hartmaier Alexander 13:13 on 17 May 2005

Re: create bug
Tony Bowden 21:21 on 17 May 2005

create bug
Hartmaier Alexander 14:49 on 18 May 2005

Re: create bug
Simon Wilcox 15:03 on 18 May 2005

Re: create bug
Perrin Harkins 15:53 on 18 May 2005

create bug
Hartmaier Alexander 15:09 on 18 May 2005

Re: create bug
Simon Wilcox 15:24 on 18 May 2005

create bug
Hartmaier Alexander 16:28 on 18 May 2005

create bug
Hartmaier Alexander 16:36 on 18 May 2005

Re: create bug
Perrin Harkins 17:49 on 18 May 2005

Re: create bug
Hartmaier Alexander 09:31 on 19 May 2005

Generated at 16:38 on 28 Jul 2005 by mariachi v0.52