hooks/syncschema.py
branchstable
changeset 6163 407f54345687
parent 6097 27e48fb7f113
child 6173 eb386e473044
child 6208 07b176640a8c
equal deleted inserted replaced
6161:c777730dfcc4 6163:407f54345687
   519                 add_inline_relation_column(session, rdefdef.subject, rtype)
   519                 add_inline_relation_column(session, rdefdef.subject, rtype)
   520             eschema = schema[rdefdef.subject]
   520             eschema = schema[rdefdef.subject]
   521             insert_rdef_on_subclasses(session, eschema, rschema, rdefdef,
   521             insert_rdef_on_subclasses(session, eschema, rschema, rdefdef,
   522                                       {'composite': entity.composite})
   522                                       {'composite': entity.composite})
   523         else:
   523         else:
       
   524             if rschema.symmetric:
       
   525                 # for symmetric relations, rdefs will store relation definitions
       
   526                 # in both ways (i.e. (subj -> obj) and (obj -> subj))
       
   527                 relation_already_defined = len(rschema.rdefs) > 2
       
   528             else:
       
   529                 relation_already_defined = len(rschema.rdefs) > 1
   524             # need to create the relation if no relation definition in the
   530             # need to create the relation if no relation definition in the
   525             # schema and if it has not been added during other event of the same
   531             # schema and if it has not been added during other event of the same
   526             # transaction
   532             # transaction
   527             if not (len(rschema.rdefs) > 1 or
   533             if not (relation_already_defined or
   528                     rtype in session.transaction_data.get('createdtables', ())):
   534                     rtype in session.transaction_data.get('createdtables', ())):
   529                 rschema = schema.rschema(rtype)
   535                 rschema = schema.rschema(rtype)
   530                 # create the necessary table
   536                 # create the necessary table
   531                 for sql in y2sql.rschema2sql(rschema).split(';'):
   537                 for sql in y2sql.rschema2sql(rschema).split(';'):
   532                     if sql.strip():
   538                     if sql.strip():