Answers.Body: <p><code>project.images</code> is an array because you are eager-loading the images.</p>
  
  <p>Since you’re only loading one project entry, you’re not actually gaining anything by eager-loading the images (or category), though. In fact, you’re actually slowing things down a bit. Eager-loading does come with a little bit of overhead, so you should only use it when you’ve got an “n+1” problem, as described on the <a href="https://docs.craftcms.com/v3/dev/eager-loading-elements.html" rel="noreferrer">Eager-Loading Entries</a> page.</p>
  
  <p>So to get this working, just remove the <code>with</code> param.</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set project = craft.entries()
      .section('projects')
      .orderBy('RAND()')
      .one() %}
  
  {% paginate project.images.limit(1) as images %}
  </code></pre>
  
  <p>Note that this will also affect how you access your category, as <code>project.category</code> will go from an eager-loaded array, back to a <a href="https://docs.craftcms.com/v3/dev/element-queries/category-queries.html" rel="noreferrer">category query</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-17T17:20:38.057Z
Answers.LastActivityDate: 2018-08-17T17:20:38.057Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>On my site I have some entries with images. In the entry template I paginate the images like so:</p>
  
  <pre><code>{% paginate entry.images.limit(1) as images %}
  </code></pre>
  
  <p>My homepage is a single random entry and I want to paginate it as well. The Problem is, paginate expects an elementcriteriamodel, not an array. So this doesn't work:</p>
  
  <pre><code>{%
  set project = craft.entries()
      .section('projects')
      .orderBy('RAND()')
      .with([
          ['images', { withTransforms: 'width' }],
          ['category']
      ])
      .one() %}
  {% paginate project.images.limit(1) as images %}
  </code></pre>
  
  <p>I tried <a href="https://craftcms.stackexchange.com/questions/14402/eager-load-and-pagination">this</a>, but that somehow doesn't work in Craft 3.</p>
  
  <pre><code>{% set queryParams = {
      with:[['images', { withTransforms: 'width' }],['category']]
  }
  %}
  
  {%
  set project = craft.entries(queryParams)
      .section('projects')
      .orderBy('RAND()')
      .one() %}
  
  {% paginate project.images.limit(1) as images %}
  </code></pre>
  
  <p>Any solutions?</p>
  
Tags: <elementcriteriamodel><pagination><array>
Title: Pagination and Entry Model on Homepage
ThreadText: # Pagination and Entry Model on Homepage
  
  (Asked by: username_0 on 2018-08-17)
  
  On my site I have some entries with images. In the entry template I paginate the images like so:
  
  ```
  {% paginate entry.images.limit(1) as images %}
  
  ```
  
  My homepage is a single random entry and I want to paginate it as well. The Problem is, paginate expects an elementcriteriamodel, not an array. So this doesn't work:
  
  ```
  {%
  set project = craft.entries()
      .section('projects')
      .orderBy('RAND()')
      .with([
          ['images', { withTransforms: 'width' }],
          ['category']
      ])
      .one() %}
  {% paginate project.images.limit(1) as images %}
  
  ```
  
  I tried [this](https://craftcms.stackexchange.com/questions/14402/eager-load-and-pagination), but that somehow doesn't work in Craft 3.
  
  ```
  {% set queryParams = {
      with:[['images', { withTransforms: 'width' }],['category']]
  }
  %}
  
  {%
  set project = craft.entries(queryParams)
      .section('projects')
      .orderBy('RAND()')
      .one() %}
  
  {% paginate project.images.limit(1) as images %}
  
  ```
  
  Any solutions?
  
  **Tags:** elementcriteriamodel, pagination, array
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-17. Score: 5 | Accepted answer
  
  `project.images` is an array because you are eager-loading the images.
  
  Since you’re only loading one project entry, you’re not actually gaining anything by eager-loading the images (or category), though. In fact, you’re actually slowing things down a bit. Eager-loading does come with a little bit of overhead, so you should only use it when you’ve got an “n+1” problem, as described on the [Eager-Loading Entries](https://docs.craftcms.com/v3/dev/eager-loading-elements.html) page.
  
  So to get this working, just remove the `with` param.
  
  ```twig
  {% set project = craft.entries()
      .section('projects')
      .orderBy('RAND()')
      .one() %}
  
  {% paginate project.images.limit(1) as images %}
  
  ```
  
  Note that this will also affect how you access your category, as `project.category` will go from an eager-loaded array, back to a [category query](https://docs.craftcms.com/v3/dev/element-queries/category-queries.html).
  
  
  ---
  
  