Hi Nigel

thanks for the help

On Wed, Jan 19, 2011 at 4:22 PM, Nigel Metheringham <
[email protected]> wrote:

> On 19 Jan 2011, at 15:05, Leandro Hermida wrote:
>
> > Couldn't find the answer to this simple question.... maybe not looking in
> the right place
> >
> > I have a standard many-to-many setup:
> >
> > person ------< person2address >------- address
> >
> > And have defined it in the standard documented way with DBIC.  How do I
> in my code, where I have an instance of the $person object and using
> relationships, delete all this person's person2address entries in one query
> without touching any addresses?
> >
> > Not sure if I am using the right jargon when I said "using relationships"
> like I saw in the manual, what I mean is that I feel this style:
> >
> > $person->cars->delete();
>
> [the example I just deleted here served only to confuse me as to what you
> meant]
>
> > How would I do it with a many-to-many just to delete the relationship
> entries?
>
>  1. Delete the bridging relationship
>        $person->person2address->delete;
>

I tried this but get Can't locate object method "person2address" via package
"MySchema::Result::Person"? What did I set up wrong?  In
MySchema::Result::Person I have for the relationship:

__PACKAGE__->has_many('person2address' =>
'MySchema::Result::Person2Address', 'person_id');
__PACKAGE__->many_to_many('addresses' => 'person2address', 'address');



>    or
>        $person->person2address_rs->delete; # works even if prefetch
>    or
>        $person->delete_related('person2address);
>
>  2. Use the additional many-to-many methods:-
>        $person->set_addresses([]);
>
>
> http://search.cpan.org/perldoc?DBIx::Class::Relationship::Base#set_$rel
>
>
>        Nigel.
>
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to