Answers.Body: <p><strong>UPDATE:</strong> </p>
  
  <p>in this case you should use <code>:empty:</code>, like this: </p>
  
  <p><code>{% set orphanBooks = craft.entries.section('books').relatedStories(':empty:') %}</code></p>
  
  <p><strong>ORIGINAL CONTENT</strong> </p>
  
  <p>According to the documentation, you can query the entries using your field handle: </p>
  
  <blockquote>
    <p>TIP</p>
    
    <p>Most custom fields support element query parameters as well, named
    after the field handles.</p>
  </blockquote>
  
  <p><a href="https://docs.craftcms.com/v3/dev/element-queries/#executing-element-queries" rel="nofollow noreferrer">https://docs.craftcms.com/v3/dev/element-queries/#executing-element-queries</a></p>
  
  <p>You might use <code>:notempty:</code> as a negative selector, just like in this query: </p>
  
  <p><code>{% set products = craft.entries.section('product').productSale(':notempty:') %}</code>  </p>
  
  <p>These SE question and answers might be helpful, too: </p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/10456/get-entries-not-related-to-categories">Get entries NOT related to categories</a></p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/452/return-entries-where-field-is-not-empty">Return entries where field is &quot;not empty&quot;</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-16T13:23:06.657Z
Answers.Text: With your code, you would finde products without a `productSale`. What the OP wants is `productSale`s that haven't been related to a product (orphans)
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-16T19:22:08.903Z
Answers.Text: Yep, you are right: updated my answer.
Answers.UserDisplayName: Ottó Radics
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-17T07:41:00.433Z
Answers.Text: This will return a list of all books, as no book has a field "relatedStories". The relation is the other way round (inverse).
Answers.UserDisplayName: Urs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-17T15:17:16.240Z
Answers.Text: Well, yeah. In this case Many to Many Field Type might be useful: https://github.com/page-8/craft-manytomany
Answers.UserDisplayName: Ottó Radics
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-14T11:45:41.587Z
Answers.LastActivityDate: 2018-09-16T19:24:28.143Z
Answers.LastEditDate: 2018-09-16T19:24:28.143Z
Answers.UserDisplayName: Ottó Radics
Body: <p>I would like to eagerload inverse relation. Business case:
  I have stories, stories are connected to books over relatedBooks field. Now I would like to query those books only which not have any story.</p>
  
  <p>I do not see any easy way to do it, so I thought that to using eagerload the related stories somehow, and filtering out the nulls
  What also could help is to just using having count somehow</p>
  
  <p>But I am not able to do it, because I am not able to lead the relatedBooks(inverse) from books perspective, only from stories.</p>
  
  <p>Tried to use the manyToMany plugin, but it is not helping either, just giving a nice interface</p>
  
  <p>Also I know I can query one-by-one but that is silly</p>
  
  <p>(last workaround would be to use hardcoded sql, but I would like to avoid this one:) )</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-12T10:01:30.233Z
Comments.Text: With eagerloading, you're referring to https://docs.craftcms.com/v3/dev/eager-loading-elements.html right?
Comments.UserDisplayName: Urs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-12T10:02:00.747Z
Comments.Text: Is this roughly the same question as https://craftcms.stackexchange.com/q/10456/8325 ? (it has no accepted answer though)
Comments.UserDisplayName: Urs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-12T10:02:35.640Z
Comments.Text: Also, you might want to post your current code sample
Comments.UserDisplayName: Urs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-14T09:38:26.817Z
Comments.Text: It sounds like you don't need "eager loading." That's a work-around for slow performance issues. You are trying to find entries in a "Books" section that have no relationships to entries in a "Stories" section. Correct?
Comments.UserDisplayName: Alex Roper
Tags: <relations><eager-loading>
Title: Eagerload inverse relation
ThreadText: # Eagerload inverse relation
  
  (Asked by: username_0 on 2018-09-11)
  
  I would like to eagerload inverse relation. Business case:
  I have stories, stories are connected to books over relatedBooks field. Now I would like to query those books only which not have any story.
  
  I do not see any easy way to do it, so I thought that to using eagerload the related stories somehow, and filtering out the nulls
  What also could help is to just using having count somehow
  
  But I am not able to do it, because I am not able to lead the relatedBooks(inverse) from books perspective, only from stories.
  
  Tried to use the manyToMany plugin, but it is not helping either, just giving a nice interface
  
  Also I know I can query one-by-one but that is silly
  
  (last workaround would be to use hardcoded sql, but I would like to avoid this one:) )
  
  **Tags:** relations, eager-loading
  
  > **Comments:**
  > **username_1**: With eagerloading, you're referring to https://docs.craftcms.com/v3/dev/eager-loading-elements.html right?  
  > **username_1**: Is this roughly the same question as https://craftcms.stackexchange.com/q/10456/8325 ? (it has no accepted answer though)  
  > **username_1**: Also, you might want to post your current code sample  
  > **username_2**: It sounds like you don't need "eager loading." That's a work-around for slow performance issues. You are trying to find entries in a "Books" section that have no relationships to entries in a "Stories" section. Correct?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2018-09-14. Score: 1
  
  **UPDATE:**
  
  in this case you should use `:empty:`, like this:
  
  `{% set orphanBooks = craft.entries.section('books').relatedStories(':empty:') %}`
  
  **ORIGINAL CONTENT**
  
  According to the documentation, you can query the entries using your field handle:
  
  > TIP
  >
  > Most custom fields support element query parameters as well, named
  > after the field handles.
  
  <https://docs.craftcms.com/v3/dev/element-queries/#executing-element-queries>
  
  You might use `:notempty:` as a negative selector, just like in this query:
  
  `{% set products = craft.entries.section('product').productSale(':notempty:') %}`
  
  These SE question and answers might be helpful, too:
  
  [Get entries NOT related to categories](https://craftcms.stackexchange.com/questions/10456/get-entries-not-related-to-categories)
  
  [Return entries where field is "not empty"](https://craftcms.stackexchange.com/questions/452/return-entries-where-field-is-not-empty)
  
  > **Comments:**
  > **username_1**: With your code, you would finde products without a `productSale`. What the OP wants is `productSale`s that haven't been related to a product (orphans)  
  > **username_3**: Yep, you are right: updated my answer.  
  > **username_1**: This will return a list of all books, as no book has a field "relatedStories". The relation is the other way round (inverse).  
  > **username_3**: Well, yeah. In this case Many to Many Field Type might be useful: https://github.com/page-8/craft-manytomany  
  
  ---
  
  