List values from database with foreignkey in grails

31 views
Skip to first unread message

nur yigit

unread,
Aug 7, 2016, 12:44:20 PM8/7/16
to Grails Dev Discuss

I'm using grails 3.1.10, spring security service and mysql. I have tables: Shop and Product. So shop has many products in my tables. product_id is fk in Shop table. listed all shop at show/index page. when clicked shop name it direct you shop/show/id which shows shop's properties. (I made this sending shop id to url) What I'm trying to do is show all product which belong to this shop. I write this method in my shopController

def list = {
params.max = Math.min(params.max? params.int('max') : 20, 100)
Product product = Product.get(params.id) 
List districts = Shop.findAllByProduct(product)
[productList : districts,
 producttInstanceTotal: Product.count()]}

and in my shop/show.gsp is

<g:each in="${productList}" status="i" var="p" >
 <div class="col-lg-2 col-md-4 col-xs-6 thumb">
    <a class="thumbnail" href="#">
      <img class="img-rounded" src="http://placehold.it/400x300" alt="">
      </a>
        <div class='text-center'>
         <p><g:link controller="product" action="show"  params="[id:p.id]">
                ${fieldValue(bean: p, field: "productName")}
            </g:link></p>
          <p>${fieldValue(bean: p, field: "productName")}</p>
          <p>${fieldValue(bean: p, field: "productBarcode")}</p>
      </div>
    </div> 
</g:each>

but nothing show. By the way I create all controllers and views using generate-all. thanks for any help 
 

Gregory Dickson

unread,
Aug 8, 2016, 4:14:15 PM8/8/16
to Grails Dev Discuss
Well, first thing, you should post this on stack overflow tagged with grails to get help on developing in Grails. This list is for the development OF Grails.

One thing, the style of your controller 'method', Grails switched to using methods instead of closures for controller methods. I can't remember the exact reason off the top of my head. So:

def list = {

}

becomes,

def list(){

Jeff Brown

unread,
Aug 12, 2016, 11:30:53 AM8/12/16
to grails-de...@googlegroups.com, Gregory Dickson


On August 8, 2016 at 3:14:31 PM, Gregory Dickson (gregory....@gmail.com) wrote:
> Well, first thing, you should post this on stack overflow tagged with
> grails to get help on developing in Grails. This list is for the
> development OF Grails.

I think asking questions about using Grails is fine for this list.

StackOverflow is fine as well, as is our Slack channel at http://grails.slack.com/.



JSB
--
Jeff Scott Brown
OCI Grails Practice Lead
Principal Software Engineer

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

Gregory Dickson

unread,
Aug 12, 2016, 1:07:52 PM8/12/16
to Grails Dev Discuss, gregory....@gmail.com
Ah, I didn't know about the Slack channel. FYI, this is the joining link: http://slack-signup.grails.org/
Reply all
Reply to author
Forward
0 new messages