odoo relationship field (association)

 

Many-to-one association

publisher_id = fields.Many2one(comodel_name= 'res.partner', domain='',context={},ondelete='',auto_join='',delegate='',string='Publisher')

    

many-to-one model field created in the data field in a table and associated with a foreign key pointing to table, wherein the database ID of the associated record. The following is a many-to-one fields available keyword arguments:

  • Ondelete action to take when deleting the definition of a related record: context is a data dictionary, can transmit information to the web client when browsing the association, such as setting default values.
    • set null (the default value): will be set to null when deleting related field
    • restricted: throw an error prevents the deletion of
    • cascade: delete the current record in the related record deleted
  • domain is a domain expression: a list of tuples to use as a filter records related logging options.
  • auto_join = True ORM using SQL allows connections when using the associated search. Will be skipped when using the access security rules, users can access security rules do not allow access to its associated records, but this SQL query would be more efficient and faster.
  • delegate = True to create a proxy inherit an associated record. Setting required = True and must ondelete = 'cascade' when used

 

One-to-many inverse association

 published_book_ids = fields.One2many(

  comodel_name= 'library.book', # related model

       inverse_name= 'publisher_id', # fields for "this" on related model
      domain='',
      context={},
     auto_join='',
     limit=0,
        string='Published Books')
 

Many-to-many关联

    author_ids = fields.Many2many(

    comodel_name = 'res.partner' , # association model (optional)
    Relation = 'library_book_res_partner_rel' , # association table
    column1 = 'A_ID' , # record associated with the present Field
    Column2 = 'the p_id' , # association table associated with the recording field
    String = 'the Authors' ) # String label text
  
    

class Many2many(_RelationalMulti):
""" Many2many field; the value of such a field is the recordset.

:param comodel_name: name of the target model (string)

The attribute ``comodel_name`` is mandatory except in the case of related
fields or field extensions.

:param relation: optional name of the table that stores the relation in
the database (string)

:param column1: optional name of the column referring to "these" records
in the table ``relation`` (string)

:param column2: optional name of the column referring to "those" records
in the table ``relation`` (string)

The attributes ``relation``, ``column1`` and ``column2`` are optional. If not
given, names are automatically generated from model names, provided
``model_name`` and ``comodel_name`` are different!

:param domain: an optional domain to set on candidate values on the
client side (domain or string)

:param context: an optional context to use on the client side when
handling that field (dictionary)

:param limit: optional limit to use upon read (integer)

"""

在创建抽象模型时,many-to-many中不要使用column1和column2属性。在 ORM 设计中对抽象模型有一个限制,如果指定关联表列名,就无法再被正常继承。
 

Guess you like

Origin www.cnblogs.com/fly-kaka/p/11018779.html