[Dbix-class] No-lurking First Post

Daniel Westermann-Clark dwc at pobox.com
Mon Sep 25 20:39:07 CEST 2006


On 2006-09-25 10:47:05 -0700, Roderick A. Anderson wrote:
> But if the case is the record already exists ( find_ ) I don't need a 
> call to rebuild a list but if it doesn't exist ( _create ) I need to 
> make the call.
> 
> The POD says it returns the $obj.  Is there elegant way to determine
> if it is a found or created object?  If not, does it make sense to
> have the something_or_otherthing methods also return which of the
> two happened?

Sounds like you want find_or_new, followed by an in_storage check:

my $obj = $rs->find_or_new({ blah => 'blarg' });
unless ($obj->in_storage) {
    $obj->insert;
    # rebuild list
    # yay!
}

-- 
Daniel Westermann-Clark



More information about the Dbix-class mailing list