Search code examples
mysqlgrailsgrails-orm

Grails domain class foreign key mapping


I'd like to ask regarding a particular issue I have.

For example, I have a Resource table that has a product_id as foreign key of table Product. Now my third table Consumer should have a foreign key resource_product_id which is exactly referring to product_id column of Resource table.

How should i map this scenario in grails domain class.

Thanks for your consideration. :)


Solution

  • Grails will handle the foreign key for you, your domains could be like this:

    class Resource {
     Product product
    }
    class Product {
      ...
    }
    class Consumer {
     Resource resource
    }