How to update Many2many field

In Odoo relational field Many2many uses special commands in order to save and remove a set of records.  In this post you can find the list of commands for this field and a short explanation for each:

  • (0, 0, values)
    Creates a new record from the provided values. The variable values must be of type dictionary.
  • (1, id, values)
    Updates the record with specified id with the value in the values.
  • (2, id)
    Removes the record with specified id from the database.
  • (3, id)
    Removes the record with specified id from the set, but not from the database.
  • (4, id)
    Adds an existing record with specified id to the set.
  • (5)
    Unlink all records from the set, like using the command “3” on every record explicitly.
  • (6, 0, ids)
    Replaces all the existing records in the set by the specified list of records in ids. This one is the same as using command “5” followed by a command “4” for each record in the list.

Commands “1″, “2”, “3”, “5” can not be used in method “create”.

Also, you can find an explanation for every command as a comment in the source code of the models module.

Leave a Reply

Your email address will not be published.