def addJoin(sqlmeta, joinDef, childUpdate=False): soClass = sqlmeta.soClass # DSM: Try to add parent properties to the current class # DSM: Only do this once if possible at object creation and once for # DSM: each new dynamic join to refresh the current class if sqlmeta.parentClass: for join in sqlmeta.parentClass.sqlmeta.joins: jname = join.joinMethodName jarn = join.addRemoveName setattr(soClass, getterName(jname), eval('lambda self: self._parent.%s' % jname)) if hasattr(join, 'remove'): setattr( soClass, 'remove' + jarn, eval('lambda self,o: self._parent.remove%s(o)' % jarn)) if hasattr(join, 'add'): setattr( soClass, 'add' + jarn, eval('lambda self,o: self._parent.add%s(o)' % jarn)) if childUpdate: makeProperties(soClass) return if joinDef: super(InheritableSQLMeta, sqlmeta).addJoin(joinDef) # DSM: Update each child class if needed and existing (only for new # DSM: dynamic join as no child classes exists at object creation) for c in sqlmeta.childClasses.values(): c.sqlmeta.addJoin(joinDef, childUpdate=True)
def addJoin(sqlmeta, joinDef, childUpdate=False): soClass = sqlmeta.soClass # DSM: Try to add parent properties to the current class # DSM: Only do this once if possible at object creation and once for # DSM: each new dynamic join to refresh the current class if sqlmeta.parentClass: for join in sqlmeta.parentClass.sqlmeta.joins: jname = join.joinMethodName jarn = join.addRemoveName setattr( soClass, getterName(jname), eval('lambda self: self._parent.%s' % jname)) if hasattr(join, 'remove'): setattr( soClass, 'remove' + jarn, eval('lambda self,o: self._parent.remove%s(o)' % jarn)) if hasattr(join, 'add'): setattr( soClass, 'add' + jarn, eval('lambda self,o: self._parent.add%s(o)' % jarn)) if childUpdate: makeProperties(soClass) return if joinDef: super(InheritableSQLMeta, sqlmeta).addJoin(joinDef) # DSM: Update each child class if needed and existing (only for new # DSM: dynamic join as no child classes exists at object creation) for c in sqlmeta.childClasses.values(): c.sqlmeta.addJoin(joinDef, childUpdate=True)
def addColumn(sqlmeta, columnDef, changeSchema=False, connection=None, childUpdate=False): soClass = sqlmeta.soClass # DSM: Try to add parent properties to the current class # DSM: Only do this once if possible at object creation and once for # DSM: each new dynamic column to refresh the current class if sqlmeta.parentClass: for col in sqlmeta.parentClass.sqlmeta.columnList: cname = col.name if cname == 'childName': continue if cname.endswith("ID"): cname = cname[:-2] setattr(soClass, getterName(cname), eval('lambda self: self._parent.%s' % cname)) if not col.immutable: def make_setfunc(cname): def setfunc(self, val): if not self.sqlmeta._creating and \ not getattr(self.sqlmeta, "row_update_sig_suppress", False): self.sqlmeta.send(events.RowUpdateSignal, self, {cname: val}) setattr(self._parent, cname, val) return setfunc setfunc = make_setfunc(cname) setattr(soClass, setterName(cname), setfunc) if childUpdate: makeProperties(soClass) return if columnDef: super(InheritableSQLMeta, sqlmeta).addColumn(columnDef, changeSchema, connection) # DSM: Update each child class if needed and existing (only for new # DSM: dynamic column as no child classes exists at object creation) if columnDef and hasattr(soClass, "q"): q = getattr(soClass.q, columnDef.name, None) else: q = None for c in sqlmeta.childClasses.values(): c.sqlmeta.addColumn(columnDef, connection=connection, childUpdate=True) if q: setattr(c.q, columnDef.name, q)
def addColumn(sqlmeta, columnDef, changeSchema=False, connection=None, childUpdate=False): soClass = sqlmeta.soClass # DSM: Try to add parent properties to the current class # DSM: Only do this once if possible at object creation and once for # DSM: each new dynamic column to refresh the current class if sqlmeta.parentClass: for col in sqlmeta.parentClass.sqlmeta.columnList: cname = col.name if cname == 'childName': continue if cname.endswith("ID"): cname = cname[:-2] setattr(soClass, getterName(cname), eval( 'lambda self: self._parent.%s' % cname)) if not col.immutable: def make_setfunc(cname): def setfunc(self, val): if not self.sqlmeta._creating and \ not getattr(self.sqlmeta, "row_update_sig_suppress", False): self.sqlmeta.send(events.RowUpdateSignal, self, {cname: val}) setattr(self._parent, cname, val) return setfunc setfunc = make_setfunc(cname) setattr(soClass, setterName(cname), setfunc) if childUpdate: makeProperties(soClass) return if columnDef: super(InheritableSQLMeta, sqlmeta).addColumn(columnDef, changeSchema, connection) # DSM: Update each child class if needed and existing (only for new # DSM: dynamic column as no child classes exists at object creation) if columnDef and hasattr(soClass, "q"): q = getattr(soClass.q, columnDef.name, None) else: q = None for c in sqlmeta.childClasses.values(): c.sqlmeta.addColumn(columnDef, connection=connection, childUpdate=True) if q: setattr(c.q, columnDef.name, q)