Skip Menu |

This queue is for tickets about the Class-DBI CPAN distribution.

Report information
The Basics
Id: 17585
Status: open
Priority: 0/
Queue: Class-DBI

People
Owner: Nobody in particular
Requestors: peterspeltz [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: _attrs returning inflated object. and not db column value
In 3.14 and maybe others , calling $obj->_attrs('has_a_col') gives back the object inflated by has_a rather than the value in that column in the database. Failing test. my $obj = __PACKAGE__->retrieve('18463'); ok ($obj, "Got $obj and obj has this -- " . $obj->Customer_id); my $c = $obj->find_column('Customer_id'); ok ($c, "got Column $c with name " . $c->name); my ($val) = $obj->_attrs($c); ok ( not ref $val ,"_attrs returns value in database"); thanks,
On Fri Feb 10 21:35:17 2006, guest wrote: Show quoted text
> In 3.14 and maybe others , calling $obj->_attrs('has_a_col') gives back > the object inflated by has_a rather than the value in that column in > the database. > > Failing test. > > my $obj = __PACKAGE__->retrieve('18463'); > ok ($obj, "Got $obj and obj has this -- " . $obj->Customer_id); > my $c = $obj->find_column('Customer_id'); > ok ($c, "got Column $c with name " . $c->name); > my ($val) = $obj->_attrs($c); > ok ( not ref $val ,"_attrs returns value in database"); > > thanks, >
Sidenote, "_attr" appears to be synonymous with "_attrs". Not sure if its intentional or a forgotten feature. ok ($obj->_attrs($c) == $obj->_attr($c), "_attr and _attrs are synonyms");
Subject: Re: [rt.cpan.org #17585] _attrs returning inflated object. and not db column value
Date: Sat, 11 Feb 2006 10:11:42 +0000
To: bug-Class-DBI [...] rt.cpan.org
From: Tony Bowden <tony [...] tmtm.com>
Guest via RT wrote: Show quoted text
> In 3.14 and maybe others , calling $obj->_attrs('has_a_col') gives back > the object inflated by has_a rather than the value in that column in > the database.
This is (mostly) correct, and is expected behaviour. This method returns whatever is currently stored in the object for that attribute. So, if the value has already been inflated to another object, then that's what it will return. Why do you think this is a bug? Perhaps the documentation needs to be clearer? Tony
Subject: Re: [rt.cpan.org #17585] _attrs returning inflated object. and not db column value
Date: Sat, 11 Feb 2006 10:13:04 +0000
To: bug-Class-DBI [...] rt.cpan.org
From: Tony Bowden <tony [...] tmtm.com>
Guest via RT wrote: Show quoted text
> Sidenote, "_attr" appears to be synonymous with "_attrs". Not sure if > its intentional or a forgotten feature.
Intentional: *_attr = \&_attrs; Makes the code read slightly cleaner when you're only fetching one attribute. Tony
From: PSPELTZ
On Sat Feb 11 05:13:32 2006, tony@tmtm.com wrote: Show quoted text
> Why do you think this is a bug? Perhaps the documentation needs to be > clearer?
The docs say this which lead me to believe its a bug. " The data within the object is modelled as a set of key-value pairs, where the keys are normalized column names (returned by find_column()), and the values are the data from the database row represented by the object. Access is via these functions: " Also the fact that I used to use _attrs when I wanted to be sure I had the exact value that is in the column in the DB and I think it worked. If it is not a bug, how do you suggest I retrieve the raw value that is/willbe in the DB from my object. Also I will ask on the list. Thanks.
On Sat Feb 11 05:13:32 2006, tony@tmtm.com wrote: Show quoted text
> Guest via RT wrote:
> > In 3.14 and maybe others , calling $obj->_attrs('has_a_col') gives back > > the object inflated by has_a rather than the value in that column in > > the database.
> > This is (mostly) correct, and is expected behaviour. > > This method returns whatever is currently stored in the object for that > attribute. So, if the value has already been inflated to another object, > then that's what it will return. > > Why do you think this is a bug? Perhaps the documentation needs to be > clearer? > > Tony
Problem is there is no way to easily get at the raw value behind an inflated object that was already selected. It could have been inflated to anything. AFAICT , you end up either having to do an new select or have code like this: if (my $type = ref $obj->my_col) { # How the hell do we get the value thats in the database??? if (eval { $obj->my_col->isa("Class::DBI") } ) { return $obj->my_col->id; } elsif (eval {$obj->my_col->isa("Time::Piece") { return $obj->my_col->mysql_datetime; } elsif (eval {$obj->my_col->isa("Date::Simple") { ... } else { die "Unknown type -- $type -- associated with $obj "; } } else { return $obj->my_col }
Subject: Re: [rt.cpan.org #17585] _attrs returning inflated object. and not db column value
Date: Sat, 11 Feb 2006 22:14:24 +0000
To: Guest via RT <bug-Class-DBI [...] rt.cpan.org>
From: Tony Bowden <tony [...] kasei.com>
On Sat, Feb 11, 2006 at 04:22:56PM -0500, Guest via RT wrote: Show quoted text
> Problem is there is no way to easily get at the raw value behind an > inflated object that was already selected. It could have been inflated > to anything. AFAICT , you end up either having to do an new select or > have code like this:
Even if this were true, the _attr* methods aren't the place for such behaviour. The plan in this regard is to store each attribute value as an object, rather than a single scalar. Amongst other benefits, this would allow the object to know the 'database value' separately from any inflated value. This is currently planned for the 3.1.x series of releases as it's a little too large a change for the current release series. In the meantime I would suggest you if you really need the raw value, you could look into using meta_info() to get the HasA relationship, and calling the deflator. Tony
On Sat Feb 11 17:15:30 2006, tony@kasei.com wrote: <snip> Show quoted text
> Tony
Thanks for the info. Looks like you are on top of it.