Body: <p>Below is the full block of code I am working with. This is part of a template for showing all businesses that belong to a sub-category. I need to load all businesses related to the current category, but in addition to that I need to group the businesses by state and list the town each business belongs to. I've asked other questions related to this before. This time I am actively trying to use Eager Loading to load each related town for each business. From there I'm hoping to pull out the state each business belongs to (this needs to be daisy chained, however, from business->town->county->region->state).</p>
  
  <p>The code below results in the following error:</p>
  
  <p><strong>CException</strong><br>
  <em>Craft\EntryModel and its behaviors do not have a method or closure named "N".</em></p>
  
  <p>And finally, here's the code:</p>
  
  <pre><code>    {% block entry_content %}
          {%
              set businesses = craft.entries.section('businesses').relatedTo(category).find({
                  with: ['bizTown']
              })
          %}
  
          {% set state = entry.bizTown.first.townCounty.first.countyRegion.first.regionState.first ?? 'N/A' %}
  
          {% set businessesByState = businesses|group(state) %}
  
          &lt;div class="container"&gt;
              &lt;div class="card"&gt;
  
                  &lt;p&gt;Businesses with video stories will have the video icon &lt;i class="fa fa-video-camera" aria-hidden="true"&gt;&lt;/i&gt; in front of their names.&lt;/p&gt;
  
                  {% if businesses|length %}
                      {% for state, businessesInState in businessesByState %}
                          &lt;ul class="three-col-list"&gt;
                              &lt;h3&gt;{{state}}&lt;/h3&gt;
                              &lt;ul&gt;
                                  {% for business in businessesInState %}
                                      &lt;li class="business-cat__item"&gt;
                                          {% if business.ytVideoId|length %}
                                              &lt;i class="fa fa-video-camera" aria-hidden="true"&gt;&lt;/i&gt;
                                          {% endif %}
                                          &lt;strong&gt;{{ business.link }}&lt;/strong&gt;&lt;br&gt;
                                          {% set twn = business.bizTown.first %}
                                          &lt;a class="business-cat__item--town" href="{{twn.url}}"&gt;{{twn.title}}&lt;/a&gt;
                                      &lt;/li&gt;
                                  {% endfor %}
                              &lt;/ul&gt;
                          &lt;/ul&gt;
                      {% endfor %}
                  {% else %}
  
                      &lt;p&gt;We apologize, we appear to be experiencing some technical difficulties…&lt;/p&gt;
  
                  {% endif %}
  
              &lt;/div&gt;
          &lt;/div&gt;
  
  
      {% endblock entry_content %}
  </code></pre>
  
  <p>There's got to be something simple I'm overlooking, or I could be approaching my problem all wrong. I feel out of my element and could use some advice/wisdom.</p>
  
  <p>Thanks!</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-01T17:40:43.513Z
Comments.Text: If you enable devMode and reproduce, you'll be able to see the compiled template in the `craft/storage/runtime/compiled_templates` folder in the stack trace the error is originating from. From there you'll see a comment with the line number from _your_ original template file. Which line in your template is generating that error?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-01T18:40:15.890Z
Comments.Text: Hmm, looks like it is saying line 1. =\ Here is a gist that includes both the full compiled template and the full actual template code: https://gist.github.com/swthate/532c9b5f279433dddf80885d9b99cea6
  
  Also, I noticed I made an embarrassing typo when trying to call "with", I had typed "width". I fixed that and the behavior persists.
Comments.UserDisplayName: Steven Thate
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-01T19:25:58.360Z
Comments.Text: Probably not your issue, but on line 52 if `state` does end up being set to `N/A`, then you're grouping by N/A right after that.  `{% set businessesByState = businesses|group('N/A') %}` Unless you've got a state defined as "N/A" you're selecting that'll be a logic error.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-01T20:37:13.957Z
Comments.Text: Removing `?? 'N/A'` changes the error, which now highlights that line 52 and says `Variable "entry" does not exist.`. Having `entry` there felt really weird, anyway! Not sure why it was there to begin with, I think it was just copied over from another template. Should line 52 be placed within a `for` loop, e.g. `for business in businesses`. That seems like it'd be the opposite of what I want though, to make the querie(s) on the page more efficient.
Comments.UserDisplayName: Steven Thate
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-08-02T03:20:53.490Z
Comments.Text: I'd probably start with that and see how it works... my guess is the queries would be similar especially if you used something like https://github.com/marionnewlevant/craft-mnbreakandcontinue
Comments.UserDisplayName: Brad Bell
Tags: <entrymodel><eager-loading>
Title: Getting "do not have method or closure named" error when trying to eager load
ThreadText: # Getting "do not have method or closure named" error when trying to eager load
  
  (Asked by: username_0 on 2017-08-01)
  
  Below is the full block of code I am working with. This is part of a template for showing all businesses that belong to a sub-category. I need to load all businesses related to the current category, but in addition to that I need to group the businesses by state and list the town each business belongs to. I've asked other questions related to this before. This time I am actively trying to use Eager Loading to load each related town for each business. From there I'm hoping to pull out the state each business belongs to (this needs to be daisy chained, however, from business->town->county->region->state).
  
  The code below results in the following error:
  
  **CException**  
  *Craft\EntryModel and its behaviors do not have a method or closure named "N".*
  
  And finally, here's the code:
  
  ```
      {% block entry_content %}
          {%
              set businesses = craft.entries.section('businesses').relatedTo(category).find({
                  with: ['bizTown']
              })
          %}
  
          {% set state = entry.bizTown.first.townCounty.first.countyRegion.first.regionState.first ?? 'N/A' %}
  
          {% set businessesByState = businesses|group(state) %}
  
          <div class="container">
              <div class="card">
  
                  <p>Businesses with video stories will have the video icon <i class="fa fa-video-camera" aria-hidden="true"></i> in front of their names.</p>
  
                  {% if businesses|length %}
                      {% for state, businessesInState in businessesByState %}
                          <ul class="three-col-list">
                              <h3>{{state}}</h3>
                              <ul>
                                  {% for business in businessesInState %}
                                      <li class="business-cat__item">
                                          {% if business.ytVideoId|length %}
                                              <i class="fa fa-video-camera" aria-hidden="true"></i>
                                          {% endif %}
                                          <strong>{{ business.link }}</strong><br>
                                          {% set twn = business.bizTown.first %}
                                          <a class="business-cat__item--town" href="{{twn.url}}">{{twn.title}}</a>
                                      </li>
                                  {% endfor %}
                              </ul>
                          </ul>
                      {% endfor %}
                  {% else %}
  
                      <p>We apologize, we appear to be experiencing some technical difficulties…</p>
  
                  {% endif %}
  
              </div>
          </div>
  
      {% endblock entry_content %}
  
  ```
  
  There's got to be something simple I'm overlooking, or I could be approaching my problem all wrong. I feel out of my element and could use some advice/wisdom.
  
  Thanks!
  
  **Tags:** entrymodel, eager-loading
  
  > **Comments:**
  > **username_1**: If you enable devMode and reproduce, you'll be able to see the compiled template in the `craft/storage/runtime/compiled_templates` folder in the stack trace the error is originating from. From there you'll see a comment with the line number from _your_ original template file. Which line in your template is generating that error?  
  > **username_0**: Hmm, looks like it is saying line 1. =\ Here is a gist that includes both the full compiled template and the full actual template code: https://gist.github.com/swthate/532c9b5f279433dddf80885d9b99cea6  Also, I noticed I made an embarrassing typo when trying to call "with", I had typed "width". I fixed that and the behavior persists.  
  > **username_1**: Probably not your issue, but on line 52 if `state` does end up being set to `N/A`, then you're grouping by N/A right after that.  `{% set businessesByState = businesses|group('N/A') %}` Unless you've got a state defined as "N/A" you're selecting that'll be a logic error.  
  > **username_0**: Removing `?? 'N/A'` changes the error, which now highlights that line 52 and says `Variable "entry" does not exist.`. Having `entry` there felt really weird, anyway! Not sure why it was there to begin with, I think it was just copied over from another template. Should line 52 be placed within a `for` loop, e.g. `for business in businesses`. That seems like it'd be the opposite of what I want though, to make the querie(s) on the page more efficient.  
  > **username_1**: I'd probably start with that and see how it works... my guess is the queries would be similar especially if you used something like https://github.com/marionnewlevant/craft-mnbreakandcontinue  
  
  ---
  
  ## 0 answers
  
  