Skip to Content
Menu
This question has been flagged
1 Reply
199 Views


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
Discard
Author

Could any one help !

Best Answer

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
Discard
Related Posts Replies Views Activity
0
Sep 23
144
2
Aug 23
20513
2
Jan 24
14889
1
Apr 17
5178
1
May 24
9576