On Thu, 1 Feb 2007, John Siracusa wrote:

> Maybe you should share that information with the database... :)

Ha :). I can think of 3 different scenarios:

1) Two columns of a table form a combined unique key, but neither
   of them can be defined UNIQUE().

2) You have a "unique key" that spans several tables:

    CREATE TABLE bars (
      id INTEGER AUTO_INCREMENT PRIMARY KEY NOT NULL,
      string VARCHAR(255),
      UNIQUE(string)
    )Type=InnoDB;

    CREATE TABLE foos (
      id INTEGER AUTO_INCREMENT PRIMARY KEY NOT NULL,
      bar_id INTEGER,
      UNIQUE(bar_id),
      FOREIGN KEY(bar_id) REFERENCES bars(id),
      INDEX(bar_id)
    )Type=InnoDB;

    my $foo = Rosetest::Foo->new(bar => { string => "moo!" });
    $foo->load(speculative => 1); # Error
    $foo->save();

3) The application isn't at liberty to change the db and must
   work with a crappy legacy schema.

-- Mike

Mike Schilli
[EMAIL PROTECTED]

> > It's something that I'm running into quite frequently:
> > I want to find out whether a matching record exists or not, and
> > load it if so. I guess it comes from using Class::DBI previously,
> > which allowed calls like
> >
> >     my $cd = Music::CD->find_or_create({ artist => 'U2', title => 'Boy' });
> >
> > Just speculating: Could this be added to the new find() method?
>
> It's something entirely different.  The only thing in common is the word
> "find".  There's already a load_or_save() Helper method, but with the word
> "load" in there, it of course needs a unique key.  I think I'd have to see
> some more requests and usage examples before adding something like the
> db_find_or_create() method posted earlier.  Right now, it seems very odd to
> me.  What does everyone else think?
>
> -John
>
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier.
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Rose-db-object mailing list
> Rose-db-object@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rose-db-object
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier.
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to