i am with this problem, i using ModelSchema to validade my API input and this give me a Database Model, it works fine, but if i use a Mapping Class Inheritance(Single Table type) the ModelSchema give me only the parent without the children attributes.
class SerialInterface(sql.Model):
type = sql.Column(sql.String(50))
polymorphic_identity = {
'polymorphic_identity': 'serial_interface',
'polymorphic_on': type,
}
id = sql.Column(types.Integer, primary_key=True)
transmission_rate = sql.Column(types.Integer)
mad_id = sql.Column(types.Integer, sql.ForeignKey('mad.id'))
serial_protocol = sql.relationship(SerialProtocol, uselist=False, cascade="all, delete-orphan")
class RS485(SerialInterface):
parity = sql.Column(EnumSmart(Parity))
data_bits = sql.Column(types.Integer)
stop_bits = sql.Column(types.Integer)
polymorphic_identity = SerialTypes.RS485.name
class SerialInterfaceForm(BaseSchema):
class Meta(BaseSchema.Meta):
model = SerialInterface
transmission_rate = Integer(required=True)
mad_id = Integer(required=True)
serial_protocol = Nested(SerialProtocolForm, required=True)
parity = EnumField(Parity, required=True)
data_bits = Integer(required=True)
stop_bits = Integer(required=True)
When i use SerialInterfaceForm().load(input_json)
it return <SerialInterface (transient 1477443543280)>
, using __dict__
: {'_sa_instance_state': <sqlalchemy.orm.state.InstanceState object at 0x00000157FE7F6550>, 'type': 'RS485', 'transmission_rate': 9600, 'mad_id': 1, 'serial_protocol': <SerialProtocol (transient 1477443544120)>}
My doubt is how i can make the Marshmallow ModelSchema return the correct child with his attributes