On Thu, Sep 06, 2007 at 02:10:32AM +0200, A. Pagaltzis wrote: > * Jason Kohles <[EMAIL PROTECTED]> [2007-08-22 16:35]: > > There is probably a cleaner way, but this is how I'm doing it > > at the moment... > > There certainly is. > > sub update_profiles { > my ( $self, @profiles ) = @_; > my %new_profile = map { ( $_, $_ ) } @profiles; > > # first kill existing profile links that don't show up in the new list > $self->profiles->search( { profile_id => { -not_in => @profile } } > )->delete; > > # then disregard profile links that are still in the database > delete @new_profile{ map { $_->profile_id } $self->profiles }; > > # and finally create the ones that aren't yet > $self->add_to_profiles( { profile_id => $_ } ) for values > %new_profile; > > return $self; > } > > Untested.
I think we really need to look at providing set_foos and remove_from_foos methods for has_many as well as many_many and trying to get them to share common code. They are after all both resultset-based. -- Matt S Trout Need help with your Catalyst or DBIx::Class project? Technical Director Want a managed development or deployment platform? Shadowcat Systems Ltd. Contact mst (at) shadowcatsystems.co.uk for a quote http://chainsawblues.vox.com/ http://www.shadowcat.co.uk/ _______________________________________________ List: http://lists.rawmode.org/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]