On Tue, Mar 26, 2002 at 09:42:34PM +0900, Tatsuhiko Miyagawa wrote:
> I use Class::DBI + DBD::mysql in mod_perl Apache::DBI enabled
> environment. I've found  SELECT LAST_INSERT_ID 
> would *sometimes* cause vizarre result in persistent connection. 

> Here's a patch for Class::DBI that fix this problem (*1) (for 0.36). 

Applied to 0.86, and available in 0.87 from
  http://www.tmtm.com/CPAN/Class-DBI-0.87.tar.gz

(I'll give it a few days before uploading to PAUSE)

Also fixes bug where tests interact strangely in 5.005.

Also includes new 'might_have' relationship mapping:

  CD->might_have(method_name => Class => (@fields_to_import));

  CD->might_have(liner_notes => LinerNotes => qw/notes/);

  my $liner_notes_object = $cd->liner_notes;
  my $notes = $cd->notes; # equivalent to $cd->liner_notes->notes;

might_have() is similar to has_many() for relationships that can have
at most one associated objects. For example, if you have a CD database
to which you want to add liner notes information, you might not want
to add a 'liner_notes' column to your main CD table even though there
is no multiplicity of relationship involved (each CD has at most one
'liner notes' field). So, we create another table with the same primary
key as this one, with which we can cross-reference.

But you don't want to have to keep writing methods to turn the the
'list' of liner_notes objects you'd get back from has_many into the
single object you'd need. So, might_have() does this work for you. It
creates you an accessor to fetch the single object back if it exists,
and it also allows you import any of its methods into your namespace.
So, in the example above, the LinerNotes class can be mostly invisible -
you can just call $cd->notes and it will call the notes method on the
correct LinerNotes object transparently for you.

Making sure you don't have namespace clashes is up to you, as is correctly
creating the objects, but I may make these simpler in later versions.
(Particularly if someone asks for them!)



Tony

Reply via email to