Sails workaround for deep populate
<p>I'm trying to deep populate a collection.</p>

<p>For example</p>

<pre><code>// UnitType.js
name: { type: 'string' }

// Unit.js
unitType: {
  model: 'unitType',
  via: '_id',
  required: true,
  index: true
}

// Product.js
unit: {
  model: 'unit',
  via: '_id',
  required: true,
  index: true
},
</code></pre>

<p>The problem is, that - as far I know from internet research deep populate like</p>

<pre><code>Product.find().populate('unit.unitType');
</code></pre>

<p>is currently not supported in sails. To achieve the result I want I currently </p>

<ul>
<li>query Products with populate <code>unit</code></li>
<li>query UnitTypes with the id from `product.unit.unitType``</li>
<li><code>.map()</code> <code>product.unit.unitType</code> with the response</li>
</ul>

<p>This is of course far from ideal. I also tried using <code>toJSON</code> in the model to "pre-populate" the <code>unitType</code> -> doesn't work since this doesn't support Promises. </p>

<p>There are quite a few threads on so and PR's on github on this issue, but so far I haven't found a solution to this problem. Is there any way to make this better?</p>