Sqlalchemy / marshmallow单代码表连接

时间:2016-08-08 19:14:29

标签: sqlalchemy marshmallow

我正在使用现有数据库实现flask rest 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"

  1. 当我使用下面的代码尝试参考时,它将返回ID而不是" Code Desc"柱,

  2. 我正在使用棉花糖。如果指定列,ItemTypeDesc = field_for(CommonCode, 'CodeDesc') 该对象将返回"<Model.xxxx.CommonCode object at 0x00F8D710>

  3. 是否有推荐的方法在sqlalchemy / marshmallow中实现公共代码表?

  4. 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'))
    

0 个答案:

没有答案