物理外键拓展

by
Odoo
v 16.0 Third Party 14
Download for v 16.0 Deploy on Odoo.sh
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 29
Technical Name db_constraint
LicenseLGPL-3
Versions 17.0 16.0
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 29
Technical Name db_constraint
LicenseLGPL-3
Versions 17.0 16.0

Postgresql数据库端不建立外键关系,odoo ORM保留外键关系

组件使用方式,在外键字段上设置属性db_constraint=False,将会在数据库层将外键关系解除,保留orm层的外键关系


class Author(models.Model):
    name = 'xcj.author'
    name = fields.Char(string="姓名")
    bookids = fields.One2many("xcj.book", "author_id", string="作品")

class Book(models.Model):
    name = 'xcj.book'
    name = fields.Char(string="数目")
    code = fields.Char(string="编号")
    authorid = fields.Many2one("xcj.author", string="作者", dbconstraint=False)
    authorids = fields.Many2many("xcj.author", "xcjbookauthors", "bookid", "authorid", string="作者", db_constraint=False)

设置为True或者不配置db_constraint

author_id = fields.Many2one("xcj.author", string="作者")
author_ids = fields.Many2many("xcj.author", "xcj_book_authors", "book_id", "author_id", string="作者")

或

author_id = fields.Many2one("xcj.author", string="作者", db_constraint=True)
author_ids = fields.Many2many("xcj.author", "xcj_book_authors", "book_id", "author_id", string="作者", db_constraint=True)

db_constraint_true.png

设置为False(将不会建立数据库层面的外键关系)


author_id = fields.Many2one("xcj.author", string="作者", db_constraint=False)
author_ids = fields.Many2many("xcj.author", "xcj_book_authors", "book_id", "author_id", string="作者", db_constraint=False)

db_constraint_false.png

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.