MCPcopy
hub / github.com/sequelize/sequelize / _findSeparate

Method _findSeparate

lib/model.js:1813–1862  ·  lib/model.js::Model._findSeparate
(results, options)

Source from the content-addressed store, hash-verified

1811 }
1812
1813 static async _findSeparate(results, options) {
1814 if (!options.include || options.raw || !results) return results;
1815
1816 const original = results;
1817 if (options.plain) results = [results];
1818
1819 if (!results.length) return original;
1820
1821 await Promise.all(options.include.map(async include => {
1822 if (!include.separate) {
1823 return await Model._findSeparate(
1824 results.reduce((memo, result) => {
1825 let associations = result.get(include.association.as);
1826
1827 class="cm">// Might be an empty belongsTo relation
1828 if (!associations) return memo;
1829
1830 class="cm">// Force array so we can concat no matter if it's 1:1 or :M
1831 if (!Array.isArray(associations)) associations = [associations];
1832
1833 for (let i = 0, len = associations.length; i !== len; ++i) {
1834 memo.push(associations[i]);
1835 }
1836 return memo;
1837 }, []),
1838 {
1839
1840 ..._.omit(options, class="st">'include', class="st">'attributes', class="st">'order', class="st">'where', class="st">'limit', class="st">'offset', class="st">'plain', class="st">'scope'),
1841 include: include.include || []
1842 }
1843 );
1844 }
1845
1846 const map = await include.association.get(results, {
1847
1848 ..._.omit(options, nonCascadingOptions),
1849 ..._.omit(include, [class="st">'parent', class="st">'association', class="st">'as', class="st">'originalAttributes'])
1850 });
1851
1852 for (const result of results) {
1853 result.set(
1854 include.association.as,
1855 map[result.get(include.association.sourceKey)],
1856 { raw: true }
1857 );
1858 }
1859 }));
1860
1861 return original;
1862 }
1863
1864 /**
1865 * Search for a single instance by its primary key._

Callers 1

findAllMethod · 0.80

Calls 3

allMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected