title: How to check for a valid object in Joi
body: <p>I have an array of objects that represent valid combinations of input to my endpoint:</p>
  
  <pre><code>const portfolios = [
    { "name": "portfolioA", "product": "productA" },
    { "name": "portfolioB", "product": "productB" },
    { "name": "portfolioB", "product": "productC" },
    { "name": "portfolioC", "product": "productD" },
    ...
  ]
  </code></pre>
  
  <p>For example, a user can request 'portfolioA' with 'productA' but not 'productB' or they can request 'portfolioB' with either 'productB' or 'productC'.</p>
  
  <p>The input I'll get will look like this:</p>
  
  <pre><code> portfolio: {
     name: "portfolioA",
     product: "productA"
   }
  </code></pre>
  
  <p>I'd like to be able to check this object against the valid objects in 'portfolios'  programmatically. I thought this could be done using <code>Joi.object().valid(portfolios)</code> but the validation fails.</p>
  
  <p>I can use when() to check against each of these manually using the schema below however the array of portfolios can change and I'd rather not have to change the validation code each time. I'd prefer to just give it an array of valid objects.</p>
  
  <pre><code>portfolio: {
    name: Joi.string().required(),
    product: Joi.string().required()
      .when('name', { is: Joi.string().valid('portfolioA'), then: Joi.string().valid('productA') })
      .when('name', { is: Joi.string().valid('portfolioB'), then: Joi.string().valid(['productB', 'productC']) })
  }
  </code></pre>
  
  <p>As a side note, when validation fails I see this instead of the string representation. </p>
  
  <pre><code> \"portfolio\" must be one of [[object Object], [object Object], [object Object], [object Object], [object Object]
  </code></pre>
  
  <p>Is there any way to check objects against an array of objects with Joi?</p>