ondelete='restrict'
-
有一个模型是
account.payment.term,这里面存储的基础数据,为了防止误删,另一个模型中引用这个模型的字段设置了ondelete属性,如下,但是没效果啊?是对于已经使用了的值没有效果。这个属性使用有什么条件限制吗?
这个属性只对m2o字段有效,m2m字段如何实现相同的效果?property_supplier_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True,string='Payment Terms',help="This payment term will be used instead of the default one for purchase orders and vendor bills", oldname="property_supplier_payment_term", ondelete='restrict') -
有一个模型是
account.payment.term,这里面存储的基础数据,为了防止误删,另一个模型中引用这个模型的字段设置了ondelete属性,如下,但是没效果啊?是对于已经使用了的值没有效果。这个属性使用有什么条件限制吗?
这个属性只对m2o字段有效,m2m字段如何实现相同的效果?property_supplier_payment_term_id = fields.Many2one('account.payment.term', company_dependent=True,string='Payment Terms',help="This payment term will be used instead of the default one for purchase orders and vendor bills", oldname="property_supplier_payment_term", ondelete='restrict')@1234567 在 ondelete='restrict' 中说:
这个属性使用有什么条件限制吗
这个属性只对many2one字段有效果,m2m字段不能使用,但m2m会建立 中间表,你在中间表的字段中,再使用这个属性,就可以变向解决
-
@1234567 在 ondelete='restrict' 中说:
这个属性使用有什么条件限制吗
这个属性只对many2one字段有效果,m2m字段不能使用,但m2m会建立 中间表,你在中间表的字段中,再使用这个属性,就可以变向解决
-
ondelete属性设置,实际上就是在数据库上创建
外键约束。
而你所针对的字段指定了company_dependent,所以该字段不再是一个普通的Many2one字段,而是一个compute 字段,其值也保存在另一个表中ir.property。参见这里
所以你对它指定外键约束就没有作用了。这个字段指定了
company_dependent,所以该字段不再是一个普通的Many2one字段,而是一个compute字段,其值也保存在另一个表中ir.property。这个变成
compute字段也是要存储的啊,是因为主要属性company_dependent,所以值是存储在ir.property中吗?那这种限制是怎么规定的,比如这个字段中,这两个属性相当于互斥的。怎么知道属性优先级的?property字段是compute字段吗? -
property字段就是一个函数字段,其读取和存储是通过函数来完成的。
ondelete属性是一个数据库层面的constraint, 你可以直接在数据库表上通过SQL来创建这个外键约束,现在这个对应的数据库字段都没有,怎么去创建这个约束。
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login