postgresql – 如何在Odoo 8中创建One2one关系?
发布时间:2020-12-13 15:52:57 所属栏目:百科 来源:网络整理
导读:我有两组展示一对一关系的数据. 我无法合并这两组数据,因为: 特定记录可能仅出现在集合A中,仅出现在集合B中,或者既出现在集合A中,也出现在集合B中;和 集合A和集合B中的记录之间的关联是暂时的,这意味着记录可以变得相关联并且可以变得不相关;和 集合A中的数
我有两组展示一对一关系的数据.
我无法合并这两组数据,因为: >特定记录可能仅出现在集合A中,仅出现在集合B中,或者既出现在集合A中,也出现在集合B中;和 当集合A中的记录与集合B中的记录相关联时,我想链接这两个记录.链接记录时,关系必须是一对一的.我如何保证这种关系是一对一的关系? 以下代码似乎很接近,但我不熟悉使用Odoo并且不确定如何分析这种方法是否保证一对一的关系. import openerp class A(openerp.models.Model): _name = 'set.a' _sql_constraints = [ ('set_b_id','unique("set_b_id")','Field set_b_id must be unique.'),] # Constrained to be unique (see SQL above) which essentially changes # this end of the Many2one relationship to a One2one relationship. (The # other end of the relationship must also be constrained.) set_b_id = openerp.fields.Many2one( comodel_name='set.b',) class B(openerp.models.Model): _name = 'set.b' # Constrained to tie with either zero keys or one key (see function # below) which essentially changes this end of the One2many # relationship to a One2one relationship. (The other end of the # relationship must also be constrained.) set_a_id = openerp.fields.One2many( comodel_name='set.a',inverse_name='set_b_id',) @openerp.api.constrains('set_a_id') def _constrains_set_a_id(self): if len(self.set_a_id) > 1: raise openerp.exceptions.ValidationError('Additional linkage failed.') 另一种方法可能是扩展openerp.fields以重新创建以前弃用的One2one关系,但我不确定是否可以干净地完成. 解决方法
在你的情况下,基本上一对一的关系在Odoo 8.0中是不可用的,它在Odoo(正式的OpenERP)中完全弃用了一个7.0或更高版本.
所以请我的建议是,不要使用一对一的关系,只需使用它作为many2one,并根据您的需要设置您的本地. 我希望我的回答可能对你有所帮助:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |