title: Issues / bad datas while retrieving result from a triple nested entity
body: <p>First of all, don't hesitate if you need more details, I'll try to be as clear as possible.</p>
  
  <p>I created a website that allows users to create mangas, by created 3 scaffolds : one for the manga itself, that has many chapters, which belongs to the manga, and has many pages inside of it.</p>
  
  <p>For a better user experience, I replaces the IDs in the URL by chapter numbers and page numbers, and used FriendlyID to have the manga's name inside the URL, so the first page from a manga's first chapter would look like the following: <code>localhost:3000/epic-manga/1/1</code>.</p>
  
  <p>Since all the routes are nested, the route itself needs three parameters: the 'manga_id', the 'chapter_number' and the 'page_number'. However, I didn't find useful to set up the manga variable since I though that Rails knew what I was talking about. However, while I was integrating the pages in my layout, I realized that Rails was displaying the wrong results :</p>
  
  <pre><code>  private
      #Peji stands for 'page' in japanese, don't ask
      def set_peji
        @chapter = Chapter.find_by(chapter_number: params[:chapter_id])
        @peji = @chapter.pejis.find_by(scan_number: params[:id])
      end
  </code></pre>
  
  <p>The Rails doc says that 'find_by' will select the first item that matches its research. When I load the page, the SQL request looks like this: <code>SELECT  'chapters'.* FROM 'chapters' WHERE 'chapters'.'chapter_number' = 1 LIMIT 1</code>. Yet, every single mangas have at least a first chapter.</p>
  
  <p>My biggest problem is that I don't really know how to setup the 'set_peji' function to limit the search to the manga that owns the chapters / pages, so I tried the following:</p>
  
  <pre><code>def set_peji
    @manga = Manga.find_by(slug: params[:manga_id])
    @chapter = @manga.chapters.find_by(chapter_number: params[:chapter_id])
    @peji = @manga.chapters.pejis.find_by(scan_number: params[:id])
  end
  </code></pre>
  
  <p>However, I have this error as a result: <code>undefined method 'pejis' for #&lt;Chapter::ActiveRecord_Associations_CollectionProxy:0x007fbe30667380&gt;</code> while targetting the line containing '@peji' (I tried replacing '@manga.chapters.pejis' by '@chapter.pejis' but it gets me a wrong result)</p>
  
  <p>I don't really have any other idea, I'm open to any suggestion.</p>
  
  <p>Thank you in advance !</p>