class Test2: id = Integer(primary_key=True) test = One2One(model=Model.Test, column_names=('other_test_id', 'other_test_id2'), backref="test2")
class Person: __db_schema__ = 'test_db_m2m_schema' name = String(primary_key=True) address = One2One(model=Model.Address, remote_columns="id", column_names="id_of_address", backref="person", nullable=False)
class Test2: id = Integer(primary_key=True) other_test_id = Integer( foreign_key=Model.Test.use('id'), nullable=False) other_test_id2 = String( foreign_key=Model.Test.use('id2'), nullable=False) test = One2One(model=Model.Test, backref="test2")
class Test2: id = Integer(primary_key=True) test_id = Integer( foreign_key=Model.Test.use('id'), nullable=False) test_id2 = String( foreign_key=Model.Test.use('id2'), nullable=False) test = One2One(model=Model.Test, remote_columns=('id', 'id2'), column_names=('test_id', 'test_id2'), backref="test2")
class PredictionModelCall(Mixin.IdColumn): """One call to a PredictionModel""" call_datetime = DateTime(label='Datetime when the model was called', default=datetime.datetime.utcnow, nullable=False) prediction_model = Many2One(label='Model that created the call', model=PredictionModel, nullable=False, one2many='model_previous_calls') prediction_inputs = One2One(label='Inputs that produced the output', model=PredictionInputVector, backref='inputs') prediction_output = String(nullable=False) def __repr__(self): msg = '<PredictionModelCall call_datetime={self.call_datetime}, prediction_model={self.prediction_model}>' return msg.format(self=self)
class Test2: @classmethod def define_table_args(cls): table_args = super(Test2, cls).define_table_args() return table_args + (ForeignKeyConstraint( [cls.test_id, cls.test_id2], ['test.id', 'test.id2']),) id = Integer(primary_key=True) test_id = Integer( foreign_key=Model.Test.use('id'), nullable=False) test_id2 = String( foreign_key=Model.Test.use('id2'), nullable=False) test = One2One(model=Model.Test, remote_columns=('id', 'id2'), column_names=('test_id', 'test_id2'), backref="test2")
class Exemple: id = Integer(primary_key=True) exemple = One2One(model='Model.Exemple', backref='exemple2') type = String(nullable=False) @classmethod def define_mapper_args(cls): mapper_args = super(Exemple, cls).define_mapper_args() if cls.__registry_name__ == 'Model.Exemple': mapper_args.update({ 'polymorphic_identity': 'exemple', 'polymorphic_on': cls.type, }) else: mapper_args.update({ 'polymorphic_identity': 'exemple2', }) return mapper_args
class PredictionModelExecutor(Mixin.IdColumn): """An executor is the part of the model that really compute Should be extended or overriden in other bloks """ prediction_model = One2One(label='Model using the executor', model=PredictionModel, backref='model_executor', nullable=False) def predict(self, features): """Pass the features to the model, let the model run and return its output""" # todo: add more possibilities: tensorflow, h2o model_name = self.prediction_model.model_name model_file_path = self.prediction_model.model_file_path logger.info('Starting prediction for {}'.format(model_name)) logger.debug('Loading model from {}'.format(model_file_path)) with open(model_file_path, 'rb') as f: model = pickle.load(f) feature_values = [f['value'] for f in features] output = model.predict(feature_values) return output
class Person: name = String(primary_key=True) address = One2One(model="Model.Address", backref="person")
class Person: __db_schema__ = 'test_other_db_schema' name = String(primary_key=True) address = One2One(model=Model.Address, backref="person")
class Test2: id = Integer(primary_key=True) test = One2One(model=Model.Test, backref="test2")
class Exemple2: id = Integer(primary_key=True) exemple = One2One(model='Model.Exemple', backref='exemple2')
def test_forbid_many2one_with_one2one(self): with pytest.raises(FieldException): Contextual(field=One2One(model='Model.System.Blok'), identity='foo')
class Person: name = String(primary_key=True) address = One2One(model=Model.Address, backref="person", one2many="persons")
class Person: name = String(primary_key=True, db_column_name="y1") address_id = Integer(db_column_name="y2", foreign_key=Model.Address.use('id')) address = One2One(model=Model.Address, backref="person")
class Person: name = String(primary_key=True, db_column_name="y1") address = One2One(model=Model.Address, backref="person")
class Test2: id = Integer(primary_key=True) name = String() test = One2One(model=Model.Test, backref='test2')
class Customer(Mixin.TeamOwner): id = Integer(primary_key=True) name = String() pet = One2One(model=Model.Pet, backref="owner")
class Person: name = String(primary_key=True) address = One2One(model=Model.Address)