Sequences and the index

[prev] [thread] [next] [Date index for 2004/05/06]

From: Humaniform
Subject: Sequences and the index
Date: 06:10 on 06 May 2004
I've just come back from a long vacation, and I've been looking at
the new stuff in 0.96. Looks very cool. I particularly appreciate all
of the effort that's been put into the documentation.

I think I've found a quirk in how the in-memory index treats new
objects that get their primary keys from sequences. Unlike new
objects where the primary key is explicitly specified, they don't
seem to be the same object as the one that's retrieved immediately
afterwards.


This code snippet:

package Loath::Media::Book;

use base Loath::Media::CDBI;

__PACKAGE__->table('book');
__PACKAGE__->columns(Essential => qw/id title author recommender
                                       noticed acquired started finished
                                       review modified/);
__PACKAGE__->sequence('seq_book');


#!/usr/bin/perl

use Loath::Media::Book;

$book1 = Loath::Media::Book->create({id=>100, title => 'title1',
author => 'author'});
$book1a = Loath::Media::Book->retrieve($book1->id);

print $book1->title . "\n";
print $book1a->title . "\n";
$book1a->title('title1a');
$book1a->update;
print $book1->title . "\n";
print $book1a->title . "\n";

$book2 = Loath::Media::Book->create({title => 'title2', author => 'author'});
$book2a = Loath::Media::Book->retrieve($book2->id);

print $book2->title . "\n";
print $book2a->title . "\n";
$book2a->title('title2a');
$book2a->update;
print $book2->title . "\n";
print $book2a->title . "\n";



Produces this output:

title1
title1
title1a
title1a
title2
title2
title2
title2a


$book2 is a different object from $book2a, but $book1 and $book1a are
the same object.

I'm using a Postgres DB, if that's relevant.

-- Aneel Nazareth -- http://eye-of-newt.com/nazareth --

Sequences and the index
Humaniform 06:10 on 06 May 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52