Grails - Search for non-native types

I am very new to grails (day 2).

Firstly, it’s hard for me to find easily visible resources (the documentation is very raw, and the tutorials are common and show only examples of “hello world” examples).

I set my domain class with relation to other data types.

class ShopCategoryPage{
//some stuff
ProductProcedure procedure;
ProductCategory category;
//some stuff
}

In my controller, I get the category identifier and the procedure identifier as parameters, and I'm trying to get the ShopCategoryPage associated with these parameters.

How do I find them? I tried to pass identifiers as procedureId or procedure_id, I tried to pass the ProductProcedure object generated by findById ...

I am not sure how to find a property that is not native.

+3
source share
3

findById, id , . get().

, . - get():

def shopCategoryPage = ShopCategoryPage.findByProcedureAndCategory(
       ProductProcedure.get(params.procedureId),
       ProductCategory.get(params.categoryId))

( )

HQL ( ) 3:

def shopCategoryPage = ShopCategoryPage.executeQuery(
   'from ShopCategoryPage p where p.procedure.id=:procedureId and p.category=:categoryId',
    [procedureId: params.procedureId.toLong(), categoryId: params.categoryId.toLong()])[0]
+3

-, ( , "hello world" ).

, , , . :

, " Grails". , "Grails in Action" , . Groovy " Groovy" - ( ).

, ShopCategoryPage, .

( ) - .

// First of all load the ProductProcedure and ProductCategory 
// I'm assuming here the request params are named 'procedureId' and 'categoryId'
ProductProcedure productProcedure = ProductProcedure.get(params.procedureId.toLong())
ProductCategory productCategory = ProductCategory .get(params.categoryId.toLong())

// Now get the ShopCategoryPage associated with these. Replace 'find' with 'findAll'
// if there could be multiple associated ShopCategoryPages
ShopCategoryPage shopCategoryPage = ShopCategoryPage.findByProcedureAndCategory(productProcedure, productCategory)

, 3 SELECT. shopCategoryPage, , " " HQL .

+4

I agree, the easiest way is to use a dynamic crawler.

In addition to Rocher and Brown's “Grails Ultimate Guide”, I’m offering the IBM developerWorks Scott Davis Mastering Grails track.

http://www.ibm.com/developerworks/views/java/libraryview.jsp?site_id=1&contentarea_by=Java&sort_by=Date&sort_order=1&start=1&end=19&topic_by=&product_by=&type_by=All%20Types&bye_gate_by&baster

+1
source

Source: https://habr.com/ru/post/1729135/


All Articles