Re: best stategry: check before create

[prev] [thread] [next] [Date index for 2005/03/18]

From: Jim Mozley
Subject: Re: best stategry: check before create
Date: 08:21 on 18 Mar 2005
Ofer Nave wrote:

> One more question:
> 
> If the 'find_or_create' always returns an object, how can I tell if it 
> was found or created?

One suggestion is to override the create method in the base class. I 
asked this question previously and Tony Bowden replied with a suggestion 
below:

On Mon, Jan 26, 2004 at 01:58:30PM +0000, Jim wrote:
 > I was looking at using find_or_create and wanted to do different actions
 > depending upon whether the data was found or was created.

At the minute there's no supported way I can think of for that.

The easiest thing I can think of is for you to override create(), either
in the single class or back up in your application parent class, to
store the information into the object that it's the result of a
creation:


sub create() {
my ($class, @args) = @_;
my $self = $class->SUPER::create(@args);
$self->{was_created} = 1;
return $self;
}

(Or perhaps use a TEMP column for this)

Tony

best stategry: check before create
Ofer Nave 07:10 on 18 Mar 2005

Re: best stategry: check before create
Ofer Nave 07:14 on 18 Mar 2005

Re: best stategry: check before create
Jim Mozley 08:21 on 18 Mar 2005

Re: best stategry: check before create
Ofer Nave 08:34 on 18 Mar 2005

Re: best stategry: check before create
Perrin Harkins 15:58 on 18 Mar 2005

Re: best stategry: check before create
Ofer Nave 22:04 on 18 Mar 2005

Re: best stategry: check before create
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 07:22 on 18 Mar 2005

Re: best stategry: check before create
Ofer Nave 07:36 on 18 Mar 2005

Generated at 15:09 on 27 Mar 2005 by mariachi v0.52