Skip to Content
Menu
This question has been flagged
3 Replies
29686 Views

Anyone can tell what are difference between one2many, many2one and many2many in odoo . what are the usage of three of those?

Avatar
Discard
Best Answer

Many2one : Store a relation against a co-model:

arel_id = fields.Many2one('res.users')

arel_id = fields.Many2one(comodel_name='res.users')

an_other_rel_id = fields.Many2one(comodel_name='res.partner', delegate=True)

Specific options:

comodel_name: name of the opposite model

delegate: set it to True to make fields of the target model accessible from the current model (corresponds to _inherits)


One2many : Store a relation against many rows of co-model:

arel_ids = fields.One2many('res.users', 'rel_id')

arel_ids = fields.One2many(comodel_name='res.users', inverse_name='rel_id')

Specific options:

comodel_name: name of the opposite model

inverse_name: relational column of the opposite model


Many2many : Store a relation against many2many rows of co-model:

arel_ids = fields.Many2many('res.users')

arel_ids = fields.Many2many(comodel_name='res.users', relation='table_name', column1='col_name', column2='other_col_name')

Specific options:

comodel_name: name of the opposite model

relation: relational table name

columns1: relational table left column name

columns2: relational table right column name

Avatar
Discard
Best Answer

hello you can refer this below website

http://serpentcs.com/serpentcs-relational-fields-in-openerp-270

https://www.odoo.com/documentation/10.0/reference/orm.html#relational-fields

Avatar
Discard
Best Answer

Hi,

You can see the difference in this page: https://www.odoo.com/documentation/10.0/howtos/backend.html#relations-between-models

It is very similar to the relationships of the databases. For example, when we transform the entity-relationship diagram to tables.

Avatar
Discard