Question regarding the use of SJS's maps & lists in the model.groovy file..

4 posts / 0 new
Last post
Rick
Offline
Joined: 12/07/2011
Question regarding the use of SJS's maps & lists in the model.groovy file..

Vincent et-al,

If I've got a table that I'm trying to declare that will have either a list or map but it's not known at the time of declaration -- only when the data is created/saved, is that possible?  It seems like I can do it in groovy without it complaining -- similar to the following :

 

Entity('anEntity', extends: 'Supplier') {
... 
list 'names' ,mandatory:true
decimal 'amount' ,mandatory:true
map 'inventory', mandatory: true
...
}

Thanks!

P.S.  Is there any sort of array type by chance?  I've got a family entity that needs to have an array of N children entities and I'm not sure what the best way to do that is.. Suggestions?

 

maxime
Offline
Joined: 06/23/2008
Hi It is possible to manage

Hi

It is possible to manage one-to-many or many-to-many relation... using keywords "reference", or "set" or "list".

See below my proposal

In this example i'm declaring a one-to-many relation from AnEntity to Person, and a second one from AnEntity to Inventory... The reverse declaration is not mandatory... Here I decided to setup only the "reverse" on Inventory... If you need a many-to-many relation you can setup two 'set' in both entities and at least on "reverse" keyword on one of them...

Hope this will be understable !

Maxime

 

 

Entity('AnEntity', extend:['Supplier'] ) {

  decimal 'amount', mandatory:true

  list 'persons', ref:'Person', mandatory:true

  set 'inventories', ref:'Inventory'

}

 

Entity ('Person') {

  string_64 'name'

}

 

Entity ('Inventory') {

  string_64 'inventoryId', mandatory:true

  reference 'anEntity', ref:'AnEntity', reverse:'AnEntity-inventories'

}

 

maxime
Offline
Joined: 06/23/2008
You can read more here :

You can read more here : http://www.jspresso.org/external/maven-site/docs/sjs-reference/html-chun...

Rick
Offline
Joined: 12/07/2011
  thanks.. that was helpful!

 

thanks.. that was helpful!