我正在使用现有数据库实现烧瓶休息 API。db 包含一个通用查找表,其中多个查找按代码类别分开。
Id = Primary Key , tablename = "CommonCode"
|id | code_category | codeValue | CodeDesc
------------------------------------------
|1 | "season" | "1" | "Summer"
|2 | "season" | "2" | "Winter"
|3 | "status" | "1" | "Success"
|4 | "status" | "2" | "Fail"
|5 | "Deleted" | "Y" | "Yes"
|6 | "Deleted" | "N" | "No"
我有很多引用“CommonCode”的表
当我尝试使用下面的代码进行参考时,它将返回 ID 而不是“代码描述”列,
我正在使用棉花糖。如果指定列,
ItemTypeDesc = field_for(CommonCode, 'CodeDesc')
则对象将返回"<Model.xxxx.CommonCode object at 0x00F8D710>
。是否有推荐的方法来实现 sqlalchemy/marshmallow 中的通用代码表?
.
ItemType = db.Column(db.String(2),db.ForeignKey('CommonCode.codeValue'))
ItemTypeDesc = db.relationship("CommonCode",
primaryjoin="and_(Othertable.ItemType==CommonCode.codeValue, "
"CommonCode.Code_Category=='season')",
collection_class=attribute_mapped_collection('CodeDesc'))