Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
3 Odpovědi
33215 Zobrazení

I wanted a simple many2one and one2many example , where in one2many relation in view file it can able to select the already added rows

Please help

Thanks and regard Abhishek

Avatar
Zrušit
Nejlepší odpověď

Hello there,

I've been confused too to understand these relationships, until I found this simple example explaining it quite well.

http://findnerd.com/list/view/Create-many2one-and-one2many-relationship-in-OpenERP/508/

Avatar
Zrušit

Good suggestion @ Youta +1

Nejlepší odpověď

 For the many to one query, one simple example can be the TITLES of Individuals corresponding to users. For E.g. While creating a customer, that particular customer can be defined any one of the TITLE from the drop down list present in the field TITLE. This is a perfect example of Many to one.


For the one to many query, one simple example can be that one particular product can be present in multiple sales order irrespective of sales order.


Hope its helps.


Cheers

Avatar
Zrušit
Nejlepší odpověď

x2y - x refers to the source model (the model having the field) y refers to the target model


1. One2One 

Not explicitly used by Odoo. 

Meaning: that every source model is related by the field to at most one target model. And vice versa. 

Logical meaning: From the source model we can uniquely determine the target model and vice versa.

Abstract Example: The social security number of a person is unique. Given the person (source model), we can uniquely determine his/her social security number (target model), and given the social security number, we can uniquely determine the person.

Usual database representation: two columns (fields) in a single table. Meaning that we don't usually use separate models. E.g.: There is no separate 'social security number' model. The 'person' model has a 'social security number' field on itself.

Odoo field type: not distinguished (keeps such data in a single table)


2. Many2One 

Meaning: source model can point to at most one target model, but many different source models can point to the same target model 

Logical meaning: From the source model field we can uniquely determine the target model. But from the target model, we can't uniquely determine the source model (there are potentially many source models pointing to it). 

Abstract Example: A customer (source model) can have just one surname (target model). However, any particular surname can be shared by different customers. Given the specific customer, we can uniquely determine his/her surname, but given the specific surname, we can't uniquely determine the customer. 

Usual database representation: column on source model pointing to target model id

Odoo field type: usually an integer type pointing to target model id (target models have array type fields pointing to sources)


3. One2Many

Meaning: the reverse of point 2 from a different perspective.

Logical meaning: From the source model field we can't uniquely determine the target model (we are potentially pointing to many target models). But from the target model, we can uniquely determine the source model. 

Abstract Example: A surname (source model) can point to many different customers. But a particular customer has just one surname.

Usual database representation: column on target model pointing to source model id

Odoo field type: usually an array of target model ids (target models have integer type field pointing to source).


4. Many2Many

Meaning: every source/target model can point to many different target/source models 

Logical meaning: we can't - as a rule - uniquely determine the target model from the source model and the source model from the target model.

Abstract Example: A person can have many nicknames and a particular nickname can potentially be shared by different people. A  person (source model) can point to many different nicknames (target models), and any nickname can point to many different persons.

Usual database representation: separate table with columns relating source model with target model. A row in such table looks like this: row_id, source_id, target_id. 

Odoo field type: usually an array pointing to the target model ids (target models have analogous fields pointing to source models).

Avatar
Zrušit