I am using factory boy with SQLAlchemy.
I am trying to create Fact objects, and I want factory boy to generate PatientDim objects that are foreign keys to Fact. But Subfactory doesn't pass the key, instead it passes the entire object to the foreignkey field.
How can I only pass the PatientDim key thru Subfactory?
Factories.py
class FactFactory(SQLAlchemyModelFactory):
class Meta:
model = models.Fact
sqlalchemy_session = common.Session
patient_id = factory.SubFactory(PatientDimFactory)
class PatientDimFactory(SQLAlchemyModelFactory):
class Meta:
model = models.PatientDim
sqlalchemy_session = common.Session
Models.py
class Fact(TimeStampedModel):
class Meta:
db_table = 'fact'
id = Column(Integer, primary_key=True)
patient_id = Column('patient_id', Integer, ForeignKey(PatientDim.__table__.c.id), nullable=False)
patient = relationship(PatientDim, foreign_keys='Fact.patient_id' )
Base = declarative_base()
class PatientDim(TimestampMixin, Base):
__tablename__ = 'patient_dim'
id = Column('id', Integer, primary_key=True)