[Dbix-class] Easy update for has_many?

Jess Robinson castaway at desert-island.me.uk
Sat Aug 25 14:39:17 GMT 2007



On Wed, 22 Aug 2007, Paul Makepeace wrote:

> I have a standard has_many linking multiple groups profiles to a
> particular user,
>
>  My::Schema::User->has_many(user_profile => 'My:Schema::UserProfile',
> 	{ 'foreign.user_uid' => 'self.uid', } );
>
> UserProfile is the link class ("join") table: user_uid, profile_uid
>
> I'd like to be able to set a bunch of profile_uids and have the ORM
> sort out which need deletion and creation. Is this possible?

I'm not missing something am I? My code does the equivalent of this:

$user->user_profiles->delete;
$user->create_realted('user_profiles', {profile_id => $_}) for @profiles;

(those can be profile objects or IDs, both work)

> I looked in the cookbook and there's examples on building the
> relationships ({has,many_to}_many) but not much (anything?) on using
> them.

::Manual::Joining should have this sorta stuff in, but may not yet.

Jess




More information about the DBIx-Class mailing list