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

Double Field Access??!?


I had a question about the ORM API. I am using the Python interface to Odoo. I am looking at this documentation:\https://www.odoo.com/documentation/11.0/reference/orm.html#field-access


The documentation shows how to access a field like so: table_name.column_name. However, there is another example like this: table_name.column_name.other_column_name. What does this mean? Please let me know if this does not make sense. 

Example

>>> record.name
Example Name

>>> record.company_id.name
Company Name

>>> record.name = "Bob"

>>> field = "name"

>>> record[field]
Bob
The above code shows there is a table called "record".  We do not know what columns are in this table however, which adds some confusion. We can see that we can access a column in the "record" table by doing this "record[field]" or like this "record.field".  What I am confused about is what this code is doing  -> \record.company_id.name. This seems  like  the code is referencing a column from another column. Something like if "record" is a table name. Then "company_id" is a column name. Then again "name" is also a column name. How does this make sense? What is returned? Why is the example database not shown? Is the example database shown somewhere else that I am missing? 


Thank-you for reading this!

Avatar
Discard
Best Answer

This is a way of navigating relationships between tables**

Sometimes the  information  in  the field is  simple,  like  'name'.

Sometimes  the  information  in  the  field  is  relational,  like  'company_id'  and  'country_id'  in  which  case  you  can  navigate  through  the  relationship  to  the  next  table  and  get  information  from  that  one,  at any number of levels.




record.name = "Anne" for record with id =  1 when the record is a User

record.name = "ACME" for record with id = 1 when the record is a Company

record.name = "United States" for record with id = 233  when the record is a Country

record.company_id.name = "ACME" for records with id = 1, 2 and 3 when the record is a User

record.company_id.country_id.name = "United States" for records with id = 1, 2 and 3 when the record is a User

record.company_id.country_id = 233 for records with id = 1, 2 and 3 when the record is a User

record.name = "United  States" for record with id = 233 when the record is a Country


** called models in Odoo because they contain:

  •  fields of simple information stored in the PostgreSQL table
  •  fields representing relationships stored in the PostgreSQL table
  •  fields of information calculated via Python that are not stored in PostgreSQL
  •  business logic defined in Python that is not stored in PostgreSQL.


Avatar
Discard
Author

So a triple-field is accessing multiple tables? How can I tell which tables are linked together? Or in other words, how can I tell which tables are related? Thank-you for the excellent answer. I think I understand. I at least have a much better understanding now than previously. :)

In Developer Model, use the FIELDS Menu. Filter for the model you are interested in, select just MANY2ONE fields and look at the Related Model column. If the column is blank for a given field, then that field contains simple information. If not, the model it is related to will be show in that column.

Author

Excellent. This is very helpful information Ray. 👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍👍 I appreciate you taking the time to help me understand this! 💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻💻

Related Posts Replies Views Activity
0
Aug 24
157
1
Jul 24
723
0
Oct 22
796
1
Mar 22
3340
1
Jun 21
2148