title: Retrieving data in ruby on rails through association
body: <p>I have three tables  Users(contains users details)  users_shifts(contains users shift mapping) and shift(it's id is in users_shift table). 
  What I'm doing is assigning multiple shifts to users and i want to retrieve all the data from users, users_shift and shift table.
  I have done the following thing :</p>
  
  <p>In user model:</p>
  
  <pre><code>has_many :users_shifts, :dependent =&gt; :destroy
  </code></pre>
  
  <p>In users_shift model :</p>
  
  <pre><code>has_one :shift
  belongs_to :user
  </code></pre>
  
  <p>In Shift Model</p>
  
  <pre><code>belongs_to :users_shift
  </code></pre>
  
  <p>In controller i have :</p>
  
  <pre><code>User.all
  </code></pre>
  
  <p>Now i want to fetch all the data in a table in view.
  I have to display users and his shift. Users detail will come from users table and shifts details will come from shifts table. Users_shift is used for users shift mapping.</p>