Building simplicidade.org: notes, projects, and occasional rants

Tip: deleting all objects in a many-to-many relation with DBIx::Class

This might be obvious to many of you, but it wasn't for me, so here it is.

If you have a many-to-many relation in DBIx::Class, you can remove all the relations with:

$self->set_RELATION_NAME([]);

The set_RELATION_NAME method is created automatically for each many-to-many relation you setup. It can receive a list of objects that will become related to $self.

The obvious

$self->set_RELATION_NAME();

will croak on you.