Re: [CDBI] problem with no primary key?

[prev] [thread] [next] [Date index for 2005/11/25]

From: Matt S Trout
Subject: Re: [CDBI] problem with no primary key?
Date: 19:25 on 25 Nov 2005
On Fri, Nov 25, 2005 at 08:00:23PM +0100, Tilman Baumann wrote:
> package LicServ::Option;
> use base 'LicServ::DBI';
> LicServ::Option->table('option');
> LicServ::Option->columns(Key =3D> qw(name product_id value));
> LicServ::Option->has_a(product_id =3D> 'LicServ::Product');

You haven't defined the Essential column group to tell Class::DBI which
columns to select when it retrieves an object.

Defining All implicitly defines Essential, if not already defined.=20

Also note that you *must* have a primary key. If you think you don't have=
 one,
the primary key is effectively all columns - i.e.

LicServ::Option->columns(All =3D> qw(name product_id value));
LicServ::Option->columns(Primary =3D> qw(name product_id value));

Will probably give you the behaviour you're looking for.
=20
> I get
> -----------
> LicServ::Option can't SELECT
> FROM option
> WHERE product_id =3D ?
> : DBD::Pg::st execute failed: FEHLER: Fehler =EF=BF=BDSyntaxfehler=EF=BF=
=BD bei =EF=BF=BDFROM=EF=BF=BD
> at character 9
> [for Statement "SELECT
> FROM option
> WHERE product_id =3D ?
> " with ParamValues: 1=3D'CBS-1'] at
> /usr/share/perl5/DBIx/ContextualFetch.pm line 52.
> at /usr/share/perl5/Class/DBI/Relationship/HasMany.pm line 118
> -----------
> on a foreach my $option ($product->options)
>=20
> FEHLER: Fehler =EF=BF=BDSyntaxfehler=EF=BF=BD bei =EF=BF=BDFROM=EF=BF=BD=
 at character 9 -> in English is
> ERROR: Error Syntaxerror near FROM at character 9
> Strangely Postgres has a german locale. I thought is was running as roo=
t
> ans so should have none... Howerver. :)
>=20
> If i type SELECT * FROM option WHERE product_id =3D 'CBS-1' i get the
> correct anser. So i think the problem is that no SELECT _what_ is given.
>=20
> Any idea how to avoid this problem?

Fix your class definition :)

Class::DBI is doing exactly what you've told it to, albeit in this case
that isn't actually particularly useful.

--=20
     Matt S Trout       Specialists in Perl consulting, web development, =
and
  Technical Director    UNIX/Linux systems architecture and automation. M=
ail
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more informat=
ion

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co=
.uk/ +

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] problem with no primary key?
Tilman Baumann 19:00 on 25 Nov 2005

Re: [CDBI] problem with no primary key?
Matt S Trout 19:25 on 25 Nov 2005

Re: [CDBI] problem with no primary key?
Tilman Baumann 19:18 on 25 Nov 2005

Generated at 14:51 on 01 Dec 2005 by mariachi v0.52