Re: Class::DBI::Relationship::IsA issues with create()
[prev]
[thread]
[next]
[Date index for 2005/02/26]
D'oh! I didn't see that you're using CDBI::R::IsA. Maybe next time I'll
actually read your message before replying.
Anyway, the doc for IsA provides a clue when it says "assuming mysql",
and makes personid an auto-incrementing pk of the person table. Notice
also that it excludes the pk in the call to create an $artist.
A quick look at the source confirms it: IsA specifically excludes the
person pk column from create, assuming that your db will provide
auto-incremented pks. As you probably already know, Oracle can't do that
OTOB. You can emulate it with Oracle sequences and triggers, though.
HTH!
David
On Sat, Feb 26, 2005 at 03:48:06PM -0500, jldommer@xxxx.xxxxx.xxx wrote:
> No, I actually am using 'Class::DBI::Relationship::IsA', not 'has_a', although
> something else that I've noticed about the 'is_a' relationship is that it
> doesn't seem to work with the 'has_many' relationship. Of course, based on the
> definition of an ISA relationship in general database terms, I'm not entirely
> sure that that is incorrect.
>
> Jennifer
>
> Quoting David Naughton <naughton@xxx.xxx>:
>
> > s/is_a/has_a/ ? I assume that's what you meant, maybe it was just a typo
> > in your message. Anyway, you'll also need to add to TestDBIsA::Person:
> >
> > TestDBIsA::Person->has_many( artists => 'TestDBIsA::Artist' );
> >
> > Does that help?
> >
> > David
> >
> > On Fri, Feb 25, 2005 at 05:52:18PM +0000, jldommer@xxxx.xxxxx.xxx wrote:
> > > Hi all,
> > >
> > > I am using 'Class::DBI::Relationship::IsA' on a simple test database, and
> > have run into problems with create(). I've set it up with a base class that
> > establishes a connection to my database, and then I've set up the classes for
> > the individual tables and declared the 'is_a' relationship.
> > >
> > > #Base class
> > > package TestDBIsA::ClassDBI;
> > > use base qw(Class::DBI);
> > > use strict;
> > > use warnings;
> > >
> > > my $dbh = TestDBIsA::ClassDBI->connection($dsn, $user, $password)|| die
> > "Database connection not made: $DBI::errstr";
> > >
> > >
> > > #Tables
> > > package TestDBIsA::Person;
> > > use base qw(TestDBIsA::ClassDBI);
> > >
> > > package TestDBIsA::Artist;
> > > use base qw(TestDBIsA::ClassDBI);
> > >
> > > TestDBIsA::Artist->is_a( 'pid' => 'TestDBIsA::Person' );
> > >
> > >
> > > I have run some simple tests and everything seems to be working with the
> > exception of create(). I have found that I can call create() on my parent,
> > 'Person', and everything works fine, but that when I call it on my child,
> > 'Artist', I get an error message.
> > >
> > > TestDBIsA::Artist->create( {
> > > artistid => 81,
> > > alias => 'Manet',
> > > pid => 2
> > > }
> > > );
> > >
> > > Can't insert new TestDBIsA::Person: DBD::Oracle::st execute failed:
> > > ORA-01400:
> > > cannot insert NULL into ("JLDOMMER"."PERSON"."PERSONID") (DBD ERROR:
> > > OCIStmtExecute) [for Statement "INSERT INTO person (personid)
> > > VALUES (?)
> > > "] at /usr/lib/perl5/site_perl/5.8.0/DBIx/ContextualFetch.pm line 51.
> > > at /usr/lib/perl5/site_perl/5.8.0/Class/DBI/Relationship/IsA.pm line
> > > 257
> > >
> > > I'm not sure what I've done wrong. Does anyone have any thoughts?
> > >
> > > Jennifer Dommer
> >
>
>