Showing posts with label What is. Show all posts
Showing posts with label What is. Show all posts

What is CRUD

Posted by Anantha Narayanan On 11:41 AM

A CRUD or short form for Create/Read/Update/Delete is a controller action that is built in grails for supporting basic inserting of data, querying of data, updating of data and deleting of data from table linked to a domain class.

In short, these common actions of users need not be coded for a domain class.

Consider the following example of a controller with just one line of code which enables this feature.


class BookController {
    static scaffold = true
}

The scaffold variable if its true, grails helps to auto-generate user actions for CRUD without a single line of code. The naming convention for controller follows the domain name. For a domain name Book a controller of BookController can be created.

This naming convention helps grails auto-identify your domain class and provide you with code for insert, query, update and delete for the domain class.

When the scaffold is created, grails automatically adds the above four user actions which are common for database access.

For more information on scaffolding refer Grails docs.

What are Transient Properties

Posted by Anantha Narayanan On 3:32 PM


Grails GORM by default creates all the properties on your domain as columns in database tables. We may not require such functionality. For Example in a user creation domain we may require the user to enter the confirm password along with password. We will definitely not require two columns in tables with same password (provided there is validation for that).

In such cases you can map properties in domain as Transient, conveying to Grails GORM not to create a column for the property. For Example:

Class Person {
  static transients = ["confirmPassswd"]

  String firstName
  String lastName
  String emailID
  String loginPasswd
  String confirmPasswd
}

In Grails it is simple enough to define such extensible features.

Recommended Post Slide Out For Blogger