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>
25 lines
706 B
JavaScript
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;
|
|
}
|