MappedManyToMany overwrite strategy

12 views
Skip to first unread message

alexmnyc

unread,
Mar 12, 2015, 5:24:58 PM3/12/15
to lif...@googlegroups.com
Guys,

What is the best practice strategy for overwriting a MappedManyToMany?

Thanks,

Alex

Diego Medina

unread,
Mar 12, 2015, 5:30:18 PM3/12/15
to Lift
what do you mean?

--
--
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

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Diego Medina
Lift/Scala consultant
di...@fmpwizard.com
http://fmpwizard.telegr.am

alexmnyc

unread,
Mar 12, 2015, 5:37:13 PM3/12/15
to lif...@googlegroups.com
As in 

class Model extends ManyToMany{
     object mtmField extends MappedManyToMany(this, OtherModel)
}

then if we have an instance of a model we are editing somewhere else:

var newValues:List[OtherModel] = List(.....)

//is this enough to guarantee that the new list "newValues" will overwrite mtmField?

model.mtmField.delete_?
model.mtmField.++= newValues:List
model.save

Diego Medina

unread,
Mar 13, 2015, 10:07:37 AM3/13/15
to Lift
I'm pretty sure that it will, it will definitely run in the same sql transaction, so it there is a problem, the whole thing would fail and let you know, instead of doing the delete but not the adding new values.

for the second line, doesn't this work:

model.mtmField(newValues)   

?

instead of .++= 

Thanks




--
--
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

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

a.mik...@gmail.com

unread,
Mar 13, 2015, 10:01:39 PM3/13/15
to lif...@googlegroups.com
Getting:

[error]  found   : List[code.model.OtherModel]
[error]  required: Int
[error]     fee.mtmField(a)

where a  is  of type List[OtherModel]

Diego Medina

unread,
Mar 13, 2015, 10:06:27 PM3/13/15
to Lift
ah, right, sorry, I was thinking of a OneToMany, but you have a ManyToMany,sorry about that, your original code is fine then


--
--
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

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

a.mik...@gmail.com

unread,
Mar 13, 2015, 10:08:25 PM3/13/15
to Lift
By the way,

.delete_? was acting funky, it would not add all items to the join table so I ended up using

mtmField.clear()
mtmField ++= List[OtherModel]


Diego Medina

unread,
Mar 13, 2015, 10:09:30 PM3/13/15
to Lift
thanks for posting your latest code

--
--
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

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

a.mik...@gmail.com

unread,
Mar 13, 2015, 10:11:40 PM3/13/15
to lif...@googlegroups.com
My pleasure.

I haven’t tested it with long lists yet. I will update the thread if I run into any oddities with this approach.

Diego Medina

unread,
Mar 13, 2015, 10:14:25 PM3/13/15
to Lift
great, and if you do run into issues, please post a sample project following these steps:
https://www.assembla.com/wiki/show/liftweb/Posting_example_code

so I have something to test out while trying to help you.

Thanks

Diego



On Fri, Mar 13, 2015 at 10:10 PM, <a.mik...@gmail.com> wrote:
My pleasure.

I haven’t tested it with long lists yet. I will update the thread if I run into any oddities with this approach.

--
--
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

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages