Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
1243 Vistas


Hi ,please I want know what is going on here !

in the sons field which is on father model (one to many) ,on sons are listed in the father record ,what does father record actually store (Sons IDs ?) ...if yes how does it stored ,is this field actually in DB dynamic array where I can ad as much sons as I want ?





Avatar
Descartar
Autor

Could any one help !

Mejor respuesta

Hii,

No , the Father record does not directly store Son IDs in the database.

The relationship is stored on the Son model , where each Son has a foreign key (father_id) pointing back to the Father.

So:

  • Odoo's One2many field in the Father model just reads data from the Many2one field in the Son model.
  • This is not a dynamic array or list stored inside the Father row — it's a relational link across tables.

Technical Structure Behind It:

Father Model:

class Father(models.Model):

    _name = 'your.father.model'

    name = fields.Char()

    sons_ids = fields.One2many('your.son.model', 'father_id', string="Sons")


Latest Model:

class Son(models.Model):

    _name = 'your.son.model'

    name = fields.Char()

    father_id = fields.Many2one('your.father.model', string="Father")


What It Looks Like in the Database:

Table: your_father_model

ID name
1 Muhammad Sbini

Table: your_son_model:

ID name father_id
1 John 1
2 Nour 1

As you can see:

  • The father_id is stored in each Last record.
  • Odoo uses this to dynamically build the list (sons_ids) in the UI and ORM.

Is it a dynamic array?

No , it's not a real array or list in the DB.

It behaves like a list in the UI (like what you saw in your screenshot), but technically, it's just:

  • A set of son records
  • Each with a father_id equal to the current Father record

I hope it is of full use.

Avatar
Descartar
Mejor respuesta

In Odoo, a One2many field stores a list of related records (not just IDs). Specifically, it links records from another model that have a Many2one reference back to the current model.

Internally, Odoo doesn't store data directly in the One2many field in the database. Instead, it is computed based on the Many2one field in the related model. So technically, the One2many field is not stored in the current model's table — it just provides a reverse relation for easy access to child records.

Example:

If a Sale Order has a One2many field order_line (pointing to sale.order.line), then the actual data is stored in sale.order.line using a Many2one field like order_id that points back to the sale.order.

Avatar
Descartar
Mejor respuesta

Hi,

You have a Father model with a field that lists sons, that's a One2many field in Odoo.

Example:

class Father(models.Model):
_name = 'my.father'

name = fields.Char(string='Father Name')
son_ids = fields.One2many('my.son', 'father_id', string="One of my sons")

class Son(models.Model):
_name = 'my.son'

name = fields.Char(string='Son Name')
father_id = fields.Many2one('my.father', string="Father")

The One2many field does NOT directly store data in the father model's database table. Instead, it works indirectly via the reverse Many2one field in the Son model. The father_id in the my.son table (DB) stores the link (foreign key).

One2many field (like the "sons" field on the father model) is a virtual relational field; it doesn't directly store any data in the father record's database table. Instead, the actual relationship is maintained through a Many2one field on the child model (in this case, each "son" record has a father_id field pointing to its parent "father"). So, when you see a list of sons under a father, Odoo is dynamically fetching all son records from the my.son table where father_id equals that father's ID. It’s not a stored list or array in the father's table; rather, it’s a reverse lookup based on the foreign key in the child model. This makes it scalable: you can add as many sons as you want, and Odoo will always pull them dynamically using a query, not by storing their IDs in the father record.


Hope it helps.

Avatar
Descartar
Mejor respuesta

Hi,

In Odoo, a one2many field (like 'sons' in your father model) doesn't actually store any data directly in the father record or table. Instead, the relationship is managed through the corresponding many2one field in the child model.

Here's what's happening:

  1. The father model has a one2many field pointing to sons: sons = fields.One2many('son.model', 'father_id', string="Sons")
  2. The son model has a many2one field pointing back to father: father_id = fields.Many2one('father.model', string="Father")
  3. In the database:
    • The father table doesn't have a column for sons
    • Each son record in the son table has a column called father_id that stores the ID of its parent

When you view a father record and see the list of sons, Odoo dynamically fetches all son records where father_id equals the current father's ID. This is done through a database query, not by accessing a stored array.

So to answer your questions directly:

  • No, the father record doesn't store sons' IDs
  • There is no array field in the database table
  • You can add as many sons as you want because each new son simply gets a new record in the son table with the appropriate father_id value

This design is a standard relational database pattern that allows for efficient storage and querying of one-to-many relationships without size limitations.

Regards,

Jishna

Accurates



Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
jul 25
21967
0
sept 23
144
2
ene 24
16094
1
abr 17
6011
1
jul 25
1822