title: Sorting by eloquent relationship in Laravel using DataTables
body: <p>I'm trying to use <a href="https://yajrabox.com/docs/laravel-datatables/6.0" rel="nofollow noreferrer">DataTables</a> to display list of Application model.
  Application model has operations:</p>
  
  <pre><code>public function operations(){
      return $this-&gt;hasMany('\App\Operation', 'application_id', 'id');
  }
  </code></pre>
  
  <p>Operations model has state:</p>
  
  <pre><code>public function state(){
      return $this-&gt;belongsTo('App\State', 'status_id', 'id');
  }
  </code></pre>
  
  <p>and operation author (user):</p>
  
  <pre><code>public function user(){
      return $this-&gt;hasOne('App\User', 'id', 'user_id');
  }
  </code></pre>
  
  <p>To enable datatable i'm using this code:</p>
  
  <pre><code>                        $(function() {
                          $('#applications-table').DataTable({
                              language: {
                                  "url": "/js/Polish.json"
                              },
                              processing: true,
                              serverSide: true,
                              ajax: '{!! route('applications.data') !!}',
                              columns: [
                                  { data: 'number', name: 'number', className: "vertical_middle", searchable: true},
                                  { data: 'operations.0.correspondence', name: 'operations.correspondence', className: "vertical_middle", orderable: false, searchable: false},
                                  { data: 'operations.0.comment', name: 'operations.comment', className: "vertical_middle", orderable: false, searchable: true},
                                  { data: 'operations.0.prognosed', name: 'operations.prognosed', className: "vertical_middle", searchable: false},
                                  { data: 'operations.0.state.name', name: 'operations.state.name', className: "vertical_middle", searchable: false},
                                  { data: 'operations.0.created_at', name: 'operations.created_at', className: "vertical_middle", type: "date", searchable: true},
  
                              ]
                          });
  
                      });
  </code></pre>
  
  <p>ApplicationController is serving data using this code</p>
  
  <pre><code>        $model = Application::with(array(
          'operations' =&gt; function ($query) {
              $query-&gt;orderByDesc('operations.created_at')-&gt;with('state')-&gt;with('user');
          }
      ));
  
      return Datatables::of($model)-&gt;make(true);
  </code></pre>
  
  <p>And finally a problem - table is rendering properly, but when I try to sort by another column than the first one I receive warning:</p>
  
  <blockquote>
    <p>DataTables warning: table id=applications-table - Requested unknown parameter 'operations.0.correspondence' for row 0.</p>
  </blockquote>
  
  <p>Honestly, I have no idea how to make it work. 
  Thank you in advance.</p>