Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework - CRUD naming convention

The CRUD module cannot convert the meaningful class name in play framework. For example, if i have a Category model and then make a Categories class in the controller folder to extend CRUD, the Category link will not appear in the admin section. However, if i rename the file into "Categorys", it will work. Is there any solution for this small issue ? Because i used to play with CakePhp and it works pretty good with all the name conventions

like image 453
Thai Tran Avatar asked Feb 02 '12 05:02

Thai Tran


1 Answers

According to documentation of CRUD module of Play framework

The controller’s class name has to be the model class name with a final ‘s’.

However, you could use @CRUD.For() annotation to customize naming of CRUD controller individually:

package controllers;

import models.Category;

@CRUD.For(Category.class)
public class Categories extends CRUD {

}

EDIT:

After a quick skimming through source code of CRUD module, I think model naming resolution is around line 260 in {location of play}/modules/crud/app/controllers/CRUD.java(for version 1.2.4):

259             String name = controllerClass.getSimpleName().replace("$", "");
260             name = "models." + name.substring(0, name.length() - 1); 

It simply finds model name by looking for the word without the last character of the controller name. (I just tested it, you could even name your CRUD controller as 'Categoryz'. And it works just fine)

So, if you really want to fix this in a 'conventional' way, you could modify line 260 of CRUD.java and utilize some library for singular-plural conversion like Inflector in ModeShape. But in my opinion, using @CRUD.For annotation is just fine and more cost-effective.

like image 56
dwi2 Avatar answered Oct 07 '22 07:10

dwi2