title: Require conditionally M2O entry per hook
body: <p>I'm currently building a simple product management, which uses status to track the products status life-cycle. I've added recently a new table called "handles" which is just <code>product_id</code> and <code>handle</code> (simple text input). For simplicity:</p>
  
  <p><a href="https://i.stack.imgur.com/smpy6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/smpy6.png" alt="enter image description here"></a></p>
  
  <p>I've create a hook.php file, which already gets loaded and works.</p>
  
  <pre class="lang-php prettyprint-override"><code>$filter = function (Payload $payload) {
    $container = Application::getInstance()-&gt;getContainer();
  
    $itemsService = new ItemsService($container);
    $item = $itemsService-&gt;find('products', $payload-&gt;get('id'), ['fields' =&gt; 'status,handles.*']);
  
    $statuss = ['detailed'];
    if (in_array($item['data']['status'], $statuss) || in_array($payload-&gt;get('status'), $statuss)) {
      if ((!$item['data']['handles'] || !count($item['data']['handles']))) {
        throw new UnprocessableEntityException('Can not publish product without handle!');
      }
  
    return $payload;
  }
  </code></pre>
  
  <p>This works flawlessly, as long as the order of updates is this:</p>
  
  <ol>
  <li>Create new <code>product</code> with status "Draft"</li>
  <li>Add new <code>handle</code> and save product</li>
  <li>Switch status to "Detailed"</li>
  </ol>
  
  <p>This works, because now I do have a "handle" and my code works (<code>count()</code> is not zero, so above check won't throw <code>UnprocessableEntityException</code>).</p>
  
  <p>But what if my steps are like this:</p>
  
  <ol>
  <li>Create new <code>product</code> with status "Detailed" (without any <code>handle</code>)</li>
  </ol>
  
  <hr>
  
  <p>I couldn't figure out how to write my hook, so I could check the relational field which isn't saved while using <code>item.create.products:before</code>.
  Any hints how I might check a relational field while it's being saved to database?</p>
  
  <p>Thanks in advance! Any help is welcome!</p>