Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQLAlchemy/Elixer问题_Python_Orm_Sqlalchemy_Python Elixir - Fatal编程技术网

Python SQLAlchemy/Elixer问题

Python SQLAlchemy/Elixer问题,python,orm,sqlalchemy,python-elixir,Python,Orm,Sqlalchemy,Python Elixir,我试图定义一个SQLAlchemy/Elixer模型,它可以描述以下关系。我有一个SSP表,它有多个POC表的外键。我已经在SSP对象中正确定义了多通关系(允许我正确地SSP.get(1).action.first\u name)。我还想添加的是这个关系的另一面,在这里我可以执行类似于POC.get(1.csa)的操作,并返回一个SSP对象列表,其中该POC被定义为idPOCCSA 我知道这对于多态关联来说是最好的,但我真的根本无法更改DB模式(创建一个新的poc2ssp表,其中包含关联类型的列

我试图定义一个SQLAlchemy/Elixer模型,它可以描述以下关系。我有一个SSP表,它有多个POC表的外键。我已经在SSP对象中正确定义了多通关系(允许我正确地
SSP.get(1).action.first\u name
)。我还想添加的是这个关系的另一面,在这里我可以执行类似于
POC.get(1.csa)的操作,并返回一个SSP对象列表,其中该POC被定义为idPOCCSA

我知道这对于多态关联来说是最好的,但我真的根本无法更改DB模式(创建一个新的poc2ssp表,其中包含关联类型的列)

有什么办法可以做到这一点吗?Elixer FAQ提供了一个利用primaryjoin和foreign_keys参数的好例子,但我在文档中找不到它们。我有点希望OneToMany()像许多OneToMany()一样支持colname参数。有点不太详细。

请尝试以下操作:

class POC(Entity):
  # ...
  #declare the one-to-many relationships
  csas = OneToMany('SSP')
  actions = OneToMany('SSP')
  # ...

class SSP(Entity):
  # ...
  #Tell Elixir how to disambiguate POC/SSP relationships by specifying
  #the inverse explicitly.
  csa = ManyToOne('POC', colname = 'idPOCCSA', inverse='csas')
  action = ManyToOne('POC', colname = 'idPOCAction', inverse='actions')
  # ...    

很好地工作,我使用了一个OneToOne()关系的inverse,没有想到要将它应用到OneToMany()。
class POC(Entity):
  # ...
  #declare the one-to-many relationships
  csas = OneToMany('SSP')
  actions = OneToMany('SSP')
  # ...

class SSP(Entity):
  # ...
  #Tell Elixir how to disambiguate POC/SSP relationships by specifying
  #the inverse explicitly.
  csa = ManyToOne('POC', colname = 'idPOCCSA', inverse='csas')
  action = ManyToOne('POC', colname = 'idPOCAction', inverse='actions')
  # ...