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
Revision 8393, 1.9 KB checked in by mnagni, 7 years ago (diff)

Stable release 0.1.0

  • Property svn:executable set to *
Line 
1
2#macro ( associationTableName $associationTable)
3#set ($rn = ${associationTable.rightTable.associatedClass.name.toLowerCase()})
4#set ($ln = ${associationTable.leftTable.associatedClass.name.toLowerCase()})
5#set ($name = "${rn}_${ln}")
6${vh.limitLenght($name)}#end
7
8#macro( tableName $tableModel)
9${tableModel.associatedClass.name.toLowerCase()}_table#end
10
11#macro( relationColumns $tableModel)
12#set ($tmn = $tableModel.associatedClass.name)
13#set ($ft = $tmn)
14#foreach( $relation in $tableModel.relationship)
15#relationColumn($tableModel, $relation, $foreach.hasNext)
16#end
17#end
18
19
20#macro(relationColumn $tableModel, $relation, $hasNext)
21#set ($tt = $relation.toTable.associatedClass.name)
22#set ($ft = $relation.fromTable.associatedClass.name)
23#set ($tmn = $tableModel.associatedClass.name)
24#if ($relation.isManyToMany())
25'${relation.name.trim()}': relationship(${tt}, secondary=#associationTableName($relation.associationTable)_table)#if($hasNext),#end
26#elseif($relation.isOneToMany())
27'${relation.name}': relationship(${tt}, primaryjoin=${tt.toLowerCase()}_table.c.${ft.toLowerCase()}_${relation.name.toLowerCase().trim()}==${tmn.toLowerCase()}_table.c.id)#if($hasNext),#end
28#elseif($relation.isOneToOne())
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
30#end
31#if($tt == $tmn)
32, remote_side=[${tmn.toLowerCase()}_table.c.${tmn.toLowerCase()}_id]
33#end
34#end
35
36
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
45#end
Note: See TracBrowser for help on using the repository browser.