source: mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm @ 8393

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/xmi2sqlalchemy/trunk/src/main/resources/global_library.vm@8393
Revision 8393, 1.9 KB checked in by mnagni, 7 years ago (diff)

Stable release 0.1.0

  • Property svn:executable set to *
RevLine 
[8084]1
2#macro ( associationTableName $associationTable)
3#set ($rn = ${associationTable.rightTable.associatedClass.name.toLowerCase()})
4#set ($ln = ${associationTable.leftTable.associatedClass.name.toLowerCase()})
[8393]5#set ($name = "${rn}_${ln}")
6${vh.limitLenght($name)}#end
[8084]7
[7996]8#macro( tableName $tableModel)
[8012]9${tableModel.associatedClass.name.toLowerCase()}_table#end
[7974]10
11#macro( relationColumns $tableModel)
[8084]12#set ($tmn = $tableModel.associatedClass.name)
13#set ($ft = $tmn)
[7974]14#foreach( $relation in $tableModel.relationship)
[8084]15#relationColumn($tableModel, $relation, $foreach.hasNext)
[7974]16#end
17#end
18
[8084]19
20#macro(relationColumn $tableModel, $relation, $hasNext)
[7974]21#set ($tt = $relation.toTable.associatedClass.name)
22#set ($ft = $relation.fromTable.associatedClass.name)
23#set ($tmn = $tableModel.associatedClass.name)
[8084]24#if ($relation.isManyToMany())
[8393]25'${relation.name.trim()}': relationship(${tt}, secondary=#associationTableName($relation.associationTable)_table)#if($hasNext),#end
[7974]26#elseif($relation.isOneToMany())
[8393]27'${relation.name}': relationship(${tt}, primaryjoin=${tt.toLowerCase()}_table.c.${ft.toLowerCase()}_${relation.name.toLowerCase().trim()}==${tmn.toLowerCase()}_table.c.id)#if($hasNext),#end
[7974]28#elseif($relation.isOneToOne())
[8393]29'${relation.name}': relationship(${tt}, uselist=False, backref='${relation.backrefName}', primaryjoin=${tt.toLowerCase()}_table.c.${ft.toLowerCase()}_${relation.name.toLowerCase().trim()}_id==${tmn.toLowerCase()}_table.c.id)#if($hasNext),#end
[8013]30#end
[7974]31#if($tt == $tmn)
[8012]32, remote_side=[${tmn.toLowerCase()}_table.c.${tmn.toLowerCase()}_id]
[7974]33#end
[7996]34#end
[7974]35
36
[7996]37#macro( inheritedClasses $tableModel)
38#set ($tln = ${tableModel.associatedClass.name.toLowerCase()})
39#if($tableModel.inherited.size() > 0)
40        #foreach( $parent in $tableModel.inherited)
41                #set ($pn = ${parent.associatedClass.name})
42                , polymorphic_on=${tln}_table.c.t_type, inherits=${pn}, polymorphic_identity='${tln}'#break#end
43#else   
44#end
[7974]45#end
Note: See TracBrowser for help on using the repository browser.