telosys-tools-bricks / telosys-cli

Telosys CLI - Command Line Interface
https://www.telosys.org/
GNU Lesser General Public License v3.0
166 stars 23 forks source link

How to create an attribute that refers to a collection ? #17

Closed fenix01 closed 5 years ago

fenix01 commented 5 years ago

Hi !

In first, I'd like to thank you for this project. I was looking for a simple code generation tool for my own python project, and this one works very nice. I don't like UML :)

I'm trying to create an entity with an attribute that refers to a collection, but it doesn't work at all. I created 2 files (one named Folders.entity and the other one named File.entity). My goal is to create a class with an attribute that refers to a list of sub documents (NoSQL).

Folders {
  id_: string ;
  name : string ;
  files: File [ ];
}

File {
    name : string;
}

During the generation, this attribute (files) doesn't exist. I put the following code in a .vm file :

#foreach( $attribute in $entity.attributes )
    $attribute.name : $attribute.type
#end

And it only displays the id_, and name attribute). Do you know where the problem comes from ? I'm using telosys (3.1.0).

l-gu commented 5 years ago

Hi !

First of all each entity requires an ID ( if you list the model's entities with "le" you shoul see a red "(!)" to indicate the invalid entities ) So add @Id for a field in each entity Example :

File {
  name : string  { @Id } ; // this field is the id 
}

Folder {
  id_: string { @Id } ;  // this field is the id 
  name : string ;
  files: File [ ];
}

Second point : each reference to another entity is a "link" You can get the links by using "$entity.links" Example :

#foreach( $link in $entity.links )
 $link.fieldName  
#end
fenix01 commented 5 years ago

Hi ! Thank you for your reply. I tried your code, and it works perfectly ! :)