Re: [Lift] Mapper ManyToMany trait fails to save added and then deleted join

49 views
Skip to first unread message

Naftoli Gugenheim

unread,
Aug 31, 2012, 5:02:04 PM8/31/12
to lif...@googlegroups.com
On Fri, Aug 31, 2012 at 2:43 PM, Timur Bobrus <timu...@gmail.com> wrote:
(which is the case when we add and remove the join before save)
Can you elaborate on that?


It's possible at the time I thought it would be the correct behavior, but I don't remember. However if it's clear to you that it's wrong then I can change it to something like removedJoins.map(_.delete_!).forall(identity).
However I'm wonderin what the correct behavior would be for saving. I think what's important is that we don't save a join when its corresponding child didn't  make it into the database. Let me know what you think it should do.

Timur Bobrus

unread,
Sep 2, 2012, 7:08:25 AM9/2/12
to lif...@googlegroups.com
I have a page where user can edit some item. Item have a many-to-many relation with a category. User can use the page to add and remove categories assigned to item  (by ajax calls doing add and remove joins). When he finishes, record is saved. User can add categories 1, 2, 3, and then (mapper object was no saved yet) remove category 1 and save. No categories are added. But the user still wants categories 2 and 3 to be added. 
Currently I 'm copying whole relation field content in list and user edits this list. When he finishes I save modified list. 
I think
 removedJoins.map(_.delete_!).forall(was_deleted_?)
would.solve this issue.


суббота, 1 сентября 2012 г., 1:02:09 UTC+4 пользователь nafg написал:

Naftoli Gugenheim

unread,
Sep 2, 2012, 7:22:35 PM9/2/12
to lif...@googlegroups.com
Oh, you mean delete_! returns false because the join does not exist in the database, right?

So then I'm thinking maybe the correct solution is actually:

removedJoins.forall(j => (!j.saved_?) || j.delete_!)

Thoughts?

Also is there an issue for it?


--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
 
 
 

Timur Bobrus

unread,
Sep 3, 2012, 2:36:06 AM9/3/12
to lif...@googlegroups.com
Yes, I think this would be the best solution.

Do you mean a ticket? There is issue for it, but it was closed because community rules state that issue should be discussed here before opening a ticket. So you can reopen https://github.com/lift/framework/issues/1316 or I (or you) can create new one.

понедельник, 3 сентября 2012 г., 3:22:40 UTC+4 пользователь nafg написал:

Timur Bobrus

unread,
Sep 3, 2012, 3:35:26 AM9/3/12
to lif...@googlegroups.com
Oh, I've noted a minor thing, may be it could be:

removedJoins.forall(j => (!j.db_can_delete_?) || j.delete_!)

which is in addition checks that join object was not deleted manually, although it seems that there is no way to call delete_! on join object stored in removedJoins list and I don't know how db_can_delete_? method will be changed in future, so may be this is unnecessary.


понедельник, 3 сентября 2012 г., 10:36:06 UTC+4 пользователь Timur Bobrus написал:
Reply all
Reply to author
Forward
0 new messages