0

I have my domain classes defined as follows, have no code in my controllers

import grails.rest.*

@Resource(formats=['json', 'xml'])
class Product {
    String name
    static hasMany = [productPrices: ProductPrice]
}

import grails.rest.*
@Resource(formats=['json', 'xml'])
class ProductPrice {
    int price
    static belongsTo = [product:Product]
}

My UrlMappings is defined as

"/products"(resources:"product")
{
    "/productprices"(resources: "productprice")
}

I have also tried the following based on SO input - but it does not work

ProductPriceController extends RestfulController<ProductPrice> {
 static responseFormats = ['json', 'xml'] 
 ProductPriceController() 
 {
    super(ProductPrice) 
 }

 @Override def index() 
 { 
    def productId = params.productId
    respond ProductPrice.where { product.id == productId }.list() 
 } 
}

I can access my data using the urls /MyApp/products and /MyApp/products/1.

However I cannot access my data at the second level e.g. and /MyApp/products/1/ productprices – It gives me a 404. I am just trying to get my basic code skeleton to work.

I am referring primarily to the post nested RESTful resources.

Note: I know that long term I need to probably implement custom controllers as described in this article Grails get child domain objects, but before that I can't seem to get this basic code to work.

Pointers appreciated.

Community
  • 1
  • 1
user1811107
  • 729
  • 3
  • 18
  • 39

0 Answers0