Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do grails domain classes have to be tied to a database?

I am a complete noob when it comes to grails (and still very noobish when it comes to groovy) so I apologise if this is a dumb question.

I am building a simple web app and I want to control portions of the domain in my app based on file system objects (i.e. directory structure and file type) rather than database data. How easy is it to do this or are the domain objects so entwined with GORM that it is not worth the effort to try?

like image 717
Michael Rutherfurd Avatar asked Aug 16 '10 01:08

Michael Rutherfurd


3 Answers

I ran into this question myself a couple of weeks ago.

You can just add the following snippet to the Domain Class.

def isAttached() 
{
   return false
}

Now it isn't connected to your database. Voila!

like image 108
MudDawg Avatar answered Sep 22 '22 03:09

MudDawg


You can also use:

class YourDomainClass {

    static mapWith = "none" // disable persistence for this domain class

See grails documentation and this answer. Appears to have been added in Grails 2.0.1 but not documented until version 2.3.0.

like image 44
GreenGiant Avatar answered Sep 20 '22 03:09

GreenGiant


There is no built-in way to map domain classes to file system objects as you've described, but equally there is no requirement that your domain classes map to a relational database. The subject of how to create a Grails app that doesn't use a relational database is addressed here and here (and possibly elsewhere).

like image 27
Dónal Avatar answered Sep 22 '22 03:09

Dónal