title: Is it possible to use 2 models in one view
body: <p>I am stuck on whether a concept is possible in SAPUI5, and as the docs can be a little hard to work with at this level of detail, I am asking this question earlier in my research path than normal. Mainly I don't want to spend too much time if there is an immediate 'No' answer.</p>
  
  <p>I have a use case of a view that is master-detail, using a JSON model, but I have to produce my own controls - I can't use a SplitApp etc.  </p>
  
  <p>The model is effectively a 2-layer deep tree, master leading to detail. Conceptually like this:</p>
  
  <pre><code>{ 
      "master": [
          {
              "name": "Master 1",
              "detail" : [
                  {
                  "name": "Detail 1-1"
                  },
                  {
                  "name": "Detail 1-2"
                  }
              ]
          },
          {
              "name": "Master 2",
              "detail" : [
                  {
                  "name": "Detail 2-1"
                  },
                  {
                  "name": "Detail 2-2"
                  }
              ]
          }
      ]
  }   
  </code></pre>
  
  <p>The UX is that there will be a selectable list of masters and when a selection is made the detail list control will be refreshed to show the details that are children of the selected master.</p>
  
  <p>I am familiar with binding a model to the view via</p>
  
  <pre><code>sap.ui.getCore().setModel(oModel) 
  this.getView().setModel(oModel)
  </code></pre>
  
  <p>but this binds all controls in the view to one model according to my learning to date.</p>
  
  <p>The options I think may be worth pursuing are:</p>
  
  <ol>
  <li>Bind a separate model to each of the master and detail controls and write custom code to switch out the detail-model when a master is selected. But how to make such bindings;</li>
  <li>Use a single model but somehow set the detail control to recognise the 'current selected' master. </li>
  <li>Use some kind of filter on the detail control. </li>
  </ol>
  
  <p>Explaining 2 further, if say I was using a table for the detail display I might have in the table def</p>
  
  <pre><code>   &lt;Table
              id="detailList"
              items="{
                  path: '/'
              }",
              ...
       &gt;
  </code></pre>
  
  <p>So I would be looking to modify the path to something like</p>
  
  <pre><code>path: '/master[n]/detail/'
  </code></pre>
  
  <p>where n represents the selected master instance.</p>
  
  <p>Is either possible, or is there another alternative, or should I give up.</p>
  
  <p>EDIT: I found this potential filter-based solution by <a href="https://archive.sap.com/discussions/thread/3463568" rel="noreferrer">Michael Herzog here</a>. His description is:</p>
  
  <blockquote>
    <p>i'll give you an example, how you can implement a matser-detail
    relationship in SAPUI5.</p>
    
    <p>Use case: When the user is clicking on a client in the first table,
    all related orders should be displayed in the second table. Orders
    from other clients should be hidden.</p>
    
    <p>So, in our view, we have two tables:</p>
    
    <ol>
    <li><p>Table: Clients</p></li>
    <li><p>Table: Orders</p></li>
    </ol>
    
    <p>After you created both tables and set up the databinding, implement
    this eventhandler on the first table:</p>
  </blockquote>
  
  <pre><code>oTableClients.attachRowSelectionChange( function(oEvent){
  
      // first, we fetch the binding context of the selected row
       var selectedRowContext = oEvent.getParameter("rowContext");
       // get the ID of the customer via rowContext. The model-object represents the data of the first table
       var selectedClientId = oModel,getProperty("id", selectedRowContext);
       // get binding of second table
       var ordersBinding = oTableOrders.getBinding();
       //create new filter to show the relevant data for the selected customer
       var oFilter = new sap.ui.model.Filter("clientId", sap.ui.model.FilterOperation.EQ, selectedClientId);
       // apply filter to binding
       ordersBinding.filter([oFilter]);
  });
  </code></pre>
  
  <p>I can see that this approach is viable for me - is there any reason why this pattern is fundamentally flawed?</p>