Guest User

Untitled

a guest
Jun 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. def save = {
  2. def id = params.id=="" ? 0 : params.id.toInteger()
  3. def p = (id>0) ? Page.findById(id) : new Page()
  4. p.properties = params
  5. def ps = PageSuite.findById(params.page_suite_id)
  6. ps.pages << p
  7. ps.save()
  8. def data = [success:true, data:[id:p.id, title:p.title, description:p.description, page_suite_id:ps.id]]
  9. render data as JSON
  10. }
  11.  
  12.  
  13. // p.id is NULL, how to get the id of the newly created Page ?
  14.  
  15.  
  16. class PageSuite {
  17. List pages
  18. static hasMany = [pages:Page]
  19. static constraints = {
  20. }
  21. static mapping = {
  22. sort 'title'
  23. }
  24. String title
  25. String description
  26. int sortorder
  27. }
  28.  
  29. class Page {
  30.  
  31. static constraints = {
  32. title()
  33. description()
  34. }
  35. static mapping = {
  36. sort sortorder:'asc'
  37. }
  38. static belongsTo = [pageSuite:PageSuite]
  39. static hasMany = [pageElements:PageElement]
  40. String title
  41. String description
  42. int sortorder
  43.  
  44. }
Add Comment
Please, Sign In to add comment