Files
odoo_source/addons/mail/static/src/model/model_utils.js
T
Sébastien Theys 8ce96ac850 [IMP] mail: rename js Model to Record
Removes confusion in technical code. An instance of Thread is a thread, by
analogy a record should be an instance of Record.

closes odoo/odoo#85359

Related: odoo/enterprise#24731
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
2022-02-24 18:42:13 +00:00

25 lines
706 B
JavaScript

/** @odoo-module **/
/**
* Follows the given related path starting from the given record, and returns
* the resulting value, or undefined if a relation can't be followed because it
* is undefined.
*
* @param {Record} record
* @param {string} relatedPath field names, dot separated to follow relations
* @returns {any}
*/
export function followRelations(record, relatedPath) {
let target = record;
for (const field of relatedPath.split('.')) {
if (!target.constructor.__fieldMap[field]) {
throw Error(`field(${field}) does not exist on ${target}`);
}
target = target[field];
if (!target) {
break;
}
}
return target;
}