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;
    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.
--
[ Nigel Metheringham             [email protected] ]
[ - Comments in this message are my own and not ITO opinion/policy - ]





_______________________________________________
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