I can't find the image
column in res_partner
table in an Odoo 9 PostgreSQL database? Where does Odoo 9 store this image field?
As of Odoo 9, many binary
fields have been modified to be stored inside the ir.attachment
model (ir_attachment
table). This was done in order to benefit from the filesystem storage (and deduplication properties) and avoid bloating the database.
This is enabled on binary fields with the attachment=True
parameter, as it is done for res.partner
's image
fields.
When active, the get()
and set()
method of the binary fields will store and retrieve the value in the ir.attachment
table. If you look at the code, you will see that the attachments use the following values to establish the link to the original record:
name
: name of the binary field, e.g. image
res_field
: name of the binary field, e.g. image
res_model
: model containing the field, e.g. res.partner
res_id
: ID of the record the binary field belongs totype
: 'binary'
datas
: virtual field with the contents of the binary field, which is actually stored on diskSo if you'd like to retrieve the ir.attachment
record holding the value of the image
of res.partner
with ID 32, you could use the following SQL:
SELECT id, store_fname FROM ir_attachment
WHERE res_model = 'res.partner' AND res_field = 'image' AND res_id = 32;
Because ir_attachment
entries use the filesystem storage by default, the actual value of the store_fname
field will give you the path to the image file inside your Odoo filestore, in the form 'ab/abcdef0123456789'
where the abc...
value is the SHA-1 hash of the file. This is how Odoo implements de-duplication of attachments: several attachments with the same file will map to the same unique file on disk.
If you'd like to modify the value of the image
field programmatically, it is strongly recommended to use the ORM API (e.g. the write()
method), to avoid creating inconsistencies or having to manually re-implement the file storage system.
References
image
field of res.partner to use it.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With