Re: using find_or_create in add_to_

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

From: Perrin Harkins
Subject: Re: using find_or_create in add_to_
Date: 17:23 on 03 Feb 2005
On Thu, 2005-02-03 at 15:28 +0000, Dave Howorth wrote:
> 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?

I'd say just write your own.  Here's an untested sketch:

sub add_or_associate_to_cds {
    my ($self, $data) = @_;

    my $cd = Music::CD->find_or_create( $data );
    $cd->artist( $self->id() );
    $cd->update();
};

- Perrin

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