[Dbix-class] Updating many-to-many relationships

Alexander Hartmaier alexander.hartmaier at t-systems.at
Wed Feb 22 10:18:15 GMT 2012


set_$helper_name replaces all rows in the link table, add_to_$helper_name a=
dds a row to the link table.
If you look at the code in DBIx::Class::Relationship::ManyToMany you see th=
at set_ deletes all rows and then calls the add_to_ method for every array =
element, so the syntax is the same.

The pod contains an example for its usage:
$actor->add_to_roles($role, { year =3D> 1995 });

The first argument is a role object, the optional second parameter a hashre=
f containing additional column data for the link table.

Am 2012-02-21 19:23, schrieb David Cantrell:

On Tue, Feb 21, 2012 at 06:24:03PM +0100, Alexander Hartmaier wrote:



You can find an example in the many_to_many relationship bridge docs:
https://metacpan.org/module/DBIx::Class::Relationship#many_to_many



Nothing helpful there I'm afraid, just an Exciting Bug (or maybe just a
not so exciting lack of documentation).

If I add this:

__PACKAGE__->many_to_many("user_roles_many_to_many" =3D> 'user_roles', 'rol=
e');

Then if I have a user who already has role 'Philosophise' and do this:

...->set_user_roles_many_to_many(
  [
    { role =3D> { name =3D> 'Philosophise' } }
  ]
);

Then it deletes all that user's records from the user_roles table (which
is, I presume, the correct behaviour before re-populating it), but then
generates this broken SQL:

SELECT role.id, role.name FROM role role WHERE ( role.role NAME 'Philosophi=
se' )

Maybe I'm calling it wrong, but it's not at all obvious what I should be
doing as I can't see any documentation for the set_$method apart from
that it exists - I ASSumed that the data should look the same as when I'm
doing an INSERT!




*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
Notice: This e-mail contains information that is confidential and may be pr=
ivileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120222/e84=
f5ab5/attachment.htm


More information about the DBIx-Class mailing list