Note that there are some explanatory texts on larger screens.

plurals
  1. POMapping legacy tables and multiple hasMany associations
    text
    copied!<p>I am attempting to map a few legacy (existing) tables to my domain objects. So far with a single 1:n mapping it has worked rather well. I have an ITEM or YFS_ITEM table which maps to an Item_Alias (YFS_ITEM_ALIAS) table (OmsItemAlias). My objects look are shown below for the associations.</p> <p>When I create or do a find on OmsItem I do indeed get back OmsItemAlias objects. The problem comes in when I look for inventoryItems for some reason this is always 0, even though I know there are items which exist in the database.</p> <pre><code>package com.fheg.orderrouter class OmsItem { String id String item String description Double unitCost String defaultProductClass String organizationCode static hasMany = [ aliases : OmsItemAlias,inventoryItems : InventoryItem] static constraints = { id(blank: false, nullable: false) item(nullable: false) description(nullable: false) unitCost(nullable: false) defaultProductClass(nullable: false) organizationCode(nullable: false) } static mapping = { table 'YFS_ITEM' version false id column:'ITEM_KEY', generator:'assigned', sqlType: 'char(24)' item column: 'ITEM_ID', sqlType: 'char(40)' description(column: 'DESCRIPTION', sqlType: 'varchar2(500)') unitCost column: 'UNIT_COST', sqlType: 'NUMBER(19,6)' defaultProductClass column: 'DEFAULT_PRODUCT_CLASS',sqlType: 'char(10)' organizationCode column: 'ORGANIZATION_CODE', sqlType: 'char(24)' aliases(sort:'aliasName', fetch: 'eager') inventoryItems( fetch: 'eager') } } </code></pre> <p>Here is the code for InventoryItem.</p> <pre><code>package com.fheg.orderrouter class InventoryItem { String id String organizationCode String uom String productClass static belongsTo = [ invItem : OmsItem ] static hasMany = [ inventorySupply : InventorySupply] static constraints = { id(blank: false, nullable: false) organizationCode(nullable: false) // invItem(nullable: false) uom(nullable: false) productClass(nullable: false) } static mapping = { table 'YFS_INVENTORY_ITEM' version false id column:'INVENTORY_ITEM_KEY', generator:'assigned' invItem column: 'ITEM_ID' organizationCode column: 'ORGANIZATION_CODE' uom column: 'UOM' productClass column:'PRODUCT_CLASS' } } </code></pre> <p>I am quite sure what I am doing wrong with regard to the belongTo/hasMany. It works fine for the aliases, but does nothing for inventoryItems. Any suggestions is are appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload