[Catalyst] many_to_many relationship always deletes then inserts

David Schmidt davewood at gmx.at
Fri Jan 2 22:40:17 GMT 2009


Hello list

I have a M:N relationship where each project can have many pictures
and vice-versa.

(projects) ---* (picture_projects) *--- (pictures)

If I edit a project I present the user a list of all pictures with
previously selected ones beeing pre-selected.

In the formfu config file I add all entries (pictures is the
many_to_many relationship of the Project DBIx Schema)
__PACKAGE__->many_to_many( pictures => 'picture_projects', 'picture_id');


projects/create.yml
---------------------------
model_config:
  model: 'DB::Projects'

- type: Select
  name: pictures
  label: Pictures
---------------------------

When I edit a Project and save it all entries in picture_projects with
project_id of the edited project are deleted and then reinserted.
But what I want is to only delete them if i actually removed them in
the editing process.

DELETE FROM picture_projects WHERE ( project_id = ? ): '3'
INSERT INTO picture_projects (picture_id, project_id) VALUES (?, ?): '2', '3'
INSERT INTO picture_projects (picture_id, project_id) VALUES (?, ?): '3', '3'

I would be very pleased about getting help here since I just redid the
entire application and ran into the same problem again.

thanks in advance

david



-- 
David Schmidt   |   http://www.fm5.at



More information about the Catalyst mailing list