我在用-
夏娃炼金术0.5
炼金术1.2.1
PyMySQL 0.8.0版
我的域定义如下:

class CommonColumns(Base):
    __abstract__ = True
    _created = Column(DateTime, default=func.now())
    _updated = Column(DateTime, default=func.now(), onupdate=func.now())
    _etag = Column(String(40))


class Host(CommonColumns):
    __tablename__ = 'host'
    cpa_id = Column(String(30), primary_key=True)
    host = Column(String(45))
    port = Column(Integer)
    instance = Column(String(20))
    status = Column(String(10))
    partnerships = relationship("Partnership", back_populates='host')


class Partnership(CommonColumns):
    __tablename__ = 'partnership'
    id = Column(Integer, primary_key=True, autoincrement=True)
    cpa_id = Column(String(30), ForeignKey('host.cpa_id'))
    service = Column(String(40))
    action = Column(String(50))
    status = Column(String(10))
    host = relationship("Host", back_populates='partnerships')

启动eve并将数据填充到数据库中之后。我可以查询主机和伙伴关系。它们还在响应中返回主机或伙伴关系ID。
对属于资源伙伴关系的某个项目的响应示例:
{
    "host": "0020",
    "id": 1,
    "service": "service1",
    "action": "action1",
    "status": "active",
    "_updated": "Tue, 30 Jan 2018 23:52:32 GMT",
    "_created": "Tue, 30 Jan 2018 23:52:32 GMT",
    "_etag": "e09fd6eb612f722ad26bf0b7f528f42d2f585d04",
    "_links": {
        "parent": {
            "title": "home",
            "href": "/"
        },
        "self": {
            "title": "Partnership",
            "href": "partnerships/1"
        },
        "collection": {
            "title": "partnerships",
            "href": "partnerships"
        }
    }
}

如何使它包含主机资源中的其他字段?在通常情况下,这需要一个连接查询,但我想知道它是否在eve中以某种方式处理。

最佳答案

您应该能够使用embedded参数:https://github.com/pyeve/eve-sqlalchemy/blob/master/docs/tutorial.rst#embedded-resources
它应该包括整个主机资源。
我不确定这是否适用于您当前的环境/版本。

10-05 23:32