I am using -
我在用 -
- eve-sqlalchemy 0.5
- SQLalchemy 1.2.1
- PyMySQL 0.8.0
My domain definitions look something like below:
我的域名定义如下所示:
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')
After booting up eve and populating the data in the database. I am able to query for hosts and partnerships. They are also returning the host or partnership ids in the response.
启动前夕并填充数据库中的数据后。我能够查询主机和合作伙伴。他们还在回复中返回主持人或伙伴关系ID。
Example response on one of the item belonging to resource partnership:
对属于资源伙伴关系的项目之一的响应示例:
{
"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"
}
}
}
How can I get it to include other fields from the host resource? This will require a join query in usual case but I wanted to know if it is handled in someway in eve.
如何让它包含主机资源中的其他字段?这通常需要连接查询,但我想知道它是否在前夕处理过。
1 个解决方案
#1
1
You should be able to use the embedded
parameter: https://github.com/pyeve/eve-sqlalchemy/blob/master/docs/tutorial.rst#embedded-resources
您应该能够使用嵌入式参数:https://github.com/pyeve/eve-sqlalchemy/blob/master/docs/tutorial.rst#embedded-resources
With &embedded={"host":1}
it should include the whole host ressource.
使用&embedded = {“host”:1}它应该包含整个主机资源。
I'm not sure if this works with your current environment / versions.
我不确定这是否适用于您当前的环境/版本。
#1
1
You should be able to use the embedded
parameter: https://github.com/pyeve/eve-sqlalchemy/blob/master/docs/tutorial.rst#embedded-resources
您应该能够使用嵌入式参数:https://github.com/pyeve/eve-sqlalchemy/blob/master/docs/tutorial.rst#embedded-resources
With &embedded={"host":1}
it should include the whole host ressource.
使用&embedded = {“host”:1}它应该包含整个主机资源。
I'm not sure if this works with your current environment / versions.
我不确定这是否适用于您当前的环境/版本。