On Oct 20, 2006, at 5:39 AM, John Siracusa wrote:

[...]
> If you know the class name already, just do this:
>
>     $record = $class->new(primarykeyfieldname => $pk)->load;

We (well, Graham) made the following manager class that gives us  
"fetch" and "fetch_or_create" methods to shorten the ->new(...)->load  
stuff and to factor out the speculative option logic.    I find it  
much cleaner in the application code ...

   - ask


package My::DB::Manager;

use base qw(Rose::DB::Object::Manager);

sub fetch {
   my $self = shift;
   my $obj = $self->object_class->new(@_);
   $obj->load(speculative => 1) ? $obj : undef;
}

sub fetch_or_create {
   my $self = shift;
   my $obj = $self->object_class->new(@_);
   $obj->load(speculative => 1);
   $obj;
}

sub create {
   shift->object_class->new(@_);
}

1;


-- 
http://askask.com/  - http://develooper.com/



-------------------------------------------------------------------------
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