List values from database with foreignkey in grails

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

List values from database with foreignkey in grails

nur yigit

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 
 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/2d6a27ee-ae84-49c8-a7c1-81df456bf9aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List values from database with foreignkey in grails

Gregory Dickson
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(){
}

On Sunday, August 7, 2016 at 11:44:20 AM UTC-5, nur yigit wrote:

down vote<a href="http://stackoverflow.com/questions/38812827/list-values-from-database-with-foreignkey-in-grails#" title="Click to mark as favorite question (click again to undo)" style="margin-right:auto;margin-bottom:2px;margin-left:auto;font-size:1px;color:rgb(0,119,204);overflow:hidden;display:block;width:40px;min-height:30px;background-image:url(&quot;img/sprites.svg?v=8c1c8cba242e&quot;),none;background-position:0px -120px;background-repeat:no-repeat" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fstackoverflow.com%2Fquestions%2F38812827%2Flist-values-from-database-with-foreignkey-in-grails%23\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF3BlDZg8dHw9bwx2XdpwI8P5jUxQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fstackoverflow.com%2Fquestions%2F38812827%2Flist-values-from-database-with-foreignkey-in-grails%23\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF3BlDZg8dHw9bwx2XdpwI8P5jUxQ&#39;;return true;">favorite

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="<a href="http://placehold.it/400x300" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fplacehold.it%2F400x300\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHEJq4a6LPgvh0KvgAQC_mUfeO8Wg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fplacehold.it%2F400x300\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHEJq4a6LPgvh0KvgAQC_mUfeO8Wg&#39;;return true;">http://placehold.it/400x300" alt="">
      </a>
        <div class='text-center'>
         <p><g:link controller="product" action="show"  params="[id:<a href="http://p.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fp.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIAR8e5XORlw08iI1aHcV7TDh77g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fp.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFIAR8e5XORlw08iI1aHcV7TDh77g&#39;;return true;">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 
 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/593ce6b5-e975-4e85-906c-bf22b52f9aa0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List values from database with foreignkey in grails

Jeff Brown


On August 8, 2016 at 3:14:31 PM, Gregory Dickson ([hidden email]) 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/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.57adeba7.140e5ef6.153e3%40ociweb.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: List values from database with foreignkey in grails

Gregory Dickson
Ah, I didn't know about the Slack channel. FYI, this is the joining link: http://slack-signup.grails.org/

On Friday, August 12, 2016 at 10:30:53 AM UTC-5, Jeff Scott Brown wrote:


On August 8, 2016 at 3:14:31 PM, Gregory Dickson (<a href="javascript:" target="_blank" gdf-obfuscated-mailto="ICDX3OuZBwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">gregory....@...) 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 <a href="http://grails.slack.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrails.slack.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEg1sM-OIR_u5YGZFbt2rRi0tE_xQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgrails.slack.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEg1sM-OIR_u5YGZFbt2rRi0tE_xQ&#39;;return true;">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
<a href="http://www.autismspeaks.org/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.autismspeaks.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHLOilSQBYB1lzLN6Ms6K6DtQY5DQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.autismspeaks.org%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHLOilSQBYB1lzLN6Ms6K6DtQY5DQ&#39;;return true;">http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/1a050887-d024-436c-9508-2d3e8e0f23e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...