Re: using find_or_create in add_to_

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

From: Tony Bowden
Subject: Re: using find_or_create in add_to_
Date: 18:46 on 03 Feb 2005
On Thu, Feb 03, 2005 at 03:28:57PM +0000, Dave Howorth wrote:
> In my application, I almost always want to do find_or_create instead of 
> create. If there's already data in the database that matches the data I 
> have, I want to refer to it, not create a duplicate record.
> So far, I've just been taking care to use find_or_create, and even 
> overriding create to give me a warning if I forget :)
> Now I've come across a case where I want to use add_to_*, like 
> $obj->add_to_a_related_table({ some => values })
> Now C-DBI-R-HasMany::_method_add_to calls create() so that's not what I 
> want. Has anybody got a neat way of dealing with this situation?

sub My::Class::DBI::BaseClass;

use base 'Class::DBI';

*create = __PACKAGE__->can('find_or_create');

1;


Tony

using find_or_create in add_to_
Dave Howorth 15:28 on 03 Feb 2005

Re: using find_or_create in add_to_
Perrin Harkins 17:23 on 03 Feb 2005

Re: using find_or_create in add_to_
Tony Bowden 18:46 on 03 Feb 2005

Generated at 21:05 on 16 Mar 2005 by mariachi v0.52