Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Product {
- // the static url to the product
- String url
- // the product's data or path to product
- // NOTE: data is being written to the file system
- String data
- // arbitrary name for product
- String name
- // subview that this product belongs to
- Subview subview
- excludedProps = ['data']
- /**
- * Called when this obj is loaded from the DB.
- * Loads the data field based on the URL field
- */
- def onLoad = {
- File file = new File(id)
- data = file.read
- }
- /**
- * Called before the model is stored to the DB. Writes the data contents to
- * the file system and updates the URL field
- */
- def beforeInsert = {
- File file = new File(id)
- file.write data
- data = ""
- url = "product/$id"
- }
- def beforeUpdate = {
- File file = new File(id)
- file.write data
- data = ""
- url = "product/$id"
- }
- def beforeDelete = {
- File file = new File(id)
- file.delete
- }
- // orm mapping to Subview
- static belongsTo = [Subview]
- static constraints = {
- data(blank:true, maxSize:5000)
- url(nullable:true)
- }
- }
Add Comment
Please, Sign In to add comment