Re: Trivial Question

[prev] [thread] [next] [Date index for 2005/06/12]

From: Emanuele Zeppieri
Subject: Re: Trivial Question
Date: 08:27 on 12 Jun 2005
> -----Original Message-----
> From: Michael G Schwern [mailto:schwern@xxxxx.xxx]=20
> Sent: Sunday, June 12, 2005 2:16 AM
> To: cdbi-talk@xxxxxx.xxxxx.xxx
> Subject: Re: Trivial Question
>=20
>=20
> On Sat, Jun 11, 2005 at 10:49:31PM +0100, Tony Bowden wrote:
> > On Sat, Jun 11, 2005 at 01:32:16PM -0700, Michael G Schwern wrote:
> > > I would presume the result of $obj->gimme_hash would be=20
> equivalent to:
> > > 	my %hash;
> > > 	foreach my $col ($obj->columns) {
> > > 		$hash{$col} =3D $obj->$col();
> > > 	}
> > > No?
> >=20
> > Well, in the general case there's all sorts of issues here=20
> with inflated
> > columns, triggers, even overriden methods.
>=20
> Shouldn't this all be taken care of due to the fact that its=20
> going through
> each column's accessor?

Not always, since the column accessor can give you an object reference
anyway.
For example, think of a CDBI class that has a /has a/ relationship with
another class (ForeignClass) on a given column.

In this case

	$obj->$col();

would give you something like

	ForeignClass=3DHASH(0x21404bc) # there is a little inexactitude
	                             # in the docs about this...

while in the corresponding DB field you have a value of the primary key
of the "foreign table".
However in string context a CDBI object reference returns the value of
the primary key (or anything returned by the stringify_self() method, if
provided), that's why it's necessary to force stringification if you
wanna export the column values in a hash, as Cees did (well, you've got
a number of other methods to get this, but they are probably more
complicated).

(Anyway what the column /values/ really are in CDBI is quite a shaded
concept, as Tony pointed out...)

> I guess it depends on what you want:=20
>  What's in
> the database or what the object presents to you.
> I'd lean towards the
> latter simply because its really easy to get the former by=20
> bypassing CDBI.

You are right: if you want exactly the db values in a hash the best
thing to do is probably to resort to raw DBI...

Ciao,
Emanuele.

(message missing)

Trivial Question
David Christensen 01:36 on 11 Jun 2005

Re: Trivial Question
Cees Hek 01:56 on 11 Jun 2005

Re: Trivial Question
David Christensen 12:58 on 11 Jun 2005

Re: Trivial Question
Tony Bowden 07:30 on 11 Jun 2005

Re: Trivial Question
Michael G Schwern 20:32 on 11 Jun 2005

Re: Trivial Question
Tony Bowden 21:49 on 11 Jun 2005

Re: Trivial Question
Michael G Schwern 00:15 on 12 Jun 2005

Re: Trivial Question
Emanuele Zeppieri 08:27 on 12 Jun 2005

Relationship question.
Rod Za 18:15 on 13 Jun 2005

Re: Relationship question.
Matt S Trout 02:07 on 14 Jun 2005

Re: Relationship question.
Aaron Trevena 08:41 on 14 Jun 2005

Re: Relationship question.
Rod Za 16:25 on 14 Jun 2005

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