Home Join tables in Grails
Reply: 1

Join tables in Grails

sita
1#
sita Published in 2017-11-28 07:09:20Z

I got two classes

class A {
    String name
    static hasMany[b:B]
    static mapping={
        b joinTable:[name:'A_B', column: 'b_id', key: 'a_id']
    }
}

class B {
    String name
}

Now I should join the table class B and A_B table where A_B store both the table id's. I wrote the query

select b.name from B b,A_B ab where b.id=ab.b_id 

but it throws an error that A_B is not mapped

elixir
2#
elixir Reply to 2017-12-05 18:36:45Z

Looks like you are trying to create a many to many relationship

class A {
    String name

    static hasMany = [b:B]

    static mapping={
        b joinTable:[name:'A_B']
    }
}

class B {
    String name

    static belongsTo = A    
    static hasMany = [b:B]

    static mapping={
        b joinTable:[name:'A_B']
    }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299923 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO