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

David Cantrell david at cantrell.org.uk
Tue Feb 21 18:23:59 GMT 2012


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" => 'user_roles', 'role');

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

...->set_user_roles_many_to_many(
  [
    { role => { name => '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 'Philosophise' )

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!

-- 
David Cantrell | Reality Engineer, Ministry of Information

    Deck of Cards: $1.29.
    "101 Solitaire Variations" book: $6.59.
    Cheap replacement for the one thing Windows is good at: priceless
        -- Shane Lazarus



More information about the DBIx-Class mailing list