George Meng
George Meng

Reputation: 11

Telosys Custom BASENAME

I am using telosys to generate some files. When generate a file per model, I have following config in templates.cfg:

dao; ${BEANNAME}dao.cfc ; sql ; dao.vm ; *

That works well.

I have small issue with my model name, the model file was generated from DB with nm command, but the model file name is not the same as table name. For example: my table is helpdesk_ticket, the model file name is helpdeskTicket.entity.

When doing code generation with the model, what I really want is to have a file generated base on table name:

helpdesk_ticket.cfc

But the file generated is helpdeskTicket.cfc (this is base on model file name)

Question 1: When generating models from DB, could I keep the model file name the same as table name?

Question 2: If I could not custom model file name when generating from DB, could I custom BASENAME so I could use table name as final generated file name instead of the entity name?

Upvotes: 0

Views: 50

Answers (2)

George Meng
George Meng

Reputation: 11

Thanks Igu for posting the answer. After searching and Googling and some testing to see how to apply Igu's answer, finally realized I could put

#if ( $entity.hasDatabaseTable() )$target.forceEntityName( $entity.databaseTable )#end

at the top of .vm file and it is all set. The file name will be generated as expected.

Upvotes: 1

lgu
lgu

Reputation: 2460

Question 1:
It's not possible to keep the original table name as the entity name during model creation from DB.

Question 2:
When a model is created from a database the table name is kept in each entity ( with @DbTable("xxx") annotation ).
So you can use it to force the "entity name" in the template file, thanks to "$target.forceEntityName(..)" function.
Example:

#if ( $entity.hasDatabaseTable() )$target.forceEntityName( $entity.databaseTable )#end

Upvotes: 0

Related Questions