Answers.Body: <pre class="lang-php prettyprint-override"><code>$element = Craft::$app-&gt;getUser()-&gt;getIdentity()-&gt;priceTable-&gt;relatedTo([
      'targetElement' =&gt; $product-&gt;id,
      'field' =&gt; 'product'
  ])-&gt;one()
  </code></pre>
  
  <p>But to be honest your code in Twig should not work as expected since you only grab the query and modify it. Your output is your search criteria, not the value of an element. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T15:58:51.297Z
Answers.Text: Thank you. (I was so close!) Yeah, I wondered about that. Not getting a deprecation warning either. Fixed in the edit.
Answers.UserDisplayName: Steve Mock
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-09T16:00:07.813Z
Answers.Text: Nothing was deprecated, you just display the criteria of your `ElementQuery` there is nothing wrong about that, it is just not what you want
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-08T21:45:41.303Z
Answers.LastActivityDate: 2018-11-08T21:54:51.197Z
Answers.LastEditDate: 2018-11-08T21:54:51.197Z
Answers.UserDisplayName: Robin Schambach
Body: <p>The following code works great in a template.</p>
  
  <pre><code>{% set priceProduct = currentUser.priceTable.relatedTo({    
      targetElement: product.id,
      field: 'product'
  }).one() %}
  
  {{ priceProduct.price }}
  </code></pre>
  
  <p>Where priceTable is a Super Table, product.id is from an entry element (we're in loop).</p>
  
  <p>'product' is an entry field in the Super Table row and 'price' is a plaintext field in the Super Table row.</p>
  
  <p>How might we go about replicating this functionality in a plugin?</p>
  
  <p>Craft Pro 3.0.29</p>
  
  <p>Super Table 2.0.11</p>
  
Tags: <plugin-development><plugin-supertable>
Title: How to get a Super Table relation in PHP?
ThreadText: # How to get a Super Table relation in PHP?
  
  (Asked by: username_0 on 2018-11-08)
  
  The following code works great in a template.
  
  ```
  {% set priceProduct = currentUser.priceTable.relatedTo({    
      targetElement: product.id,
      field: 'product'
  }).one() %}
  
  {{ priceProduct.price }}
  
  ```
  
  Where priceTable is a Super Table, product.id is from an entry element (we're in loop).
  
  'product' is an entry field in the Super Table row and 'price' is a plaintext field in the Super Table row.
  
  How might we go about replicating this functionality in a plugin?
  
  Craft Pro 3.0.29
  
  Super Table 2.0.11
  
  **Tags:** plugin-development, plugin-supertable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-11-08. Score: 5 | Accepted answer
  
  ```php
  $element = Craft::$app->getUser()->getIdentity()->priceTable->relatedTo([
      'targetElement' => $product->id,
      'field' => 'product'
  ])->one()
  
  ```
  
  But to be honest your code in Twig should not work as expected since you only grab the query and modify it. Your output is your search criteria, not the value of an element.
  
  > **Comments:**
  > **username_0**: Thank you. (I was so close!) Yeah, I wondered about that. Not getting a deprecation warning either. Fixed in the edit.  
  > **username_1**: Nothing was deprecated, you just display the criteria of your `ElementQuery` there is nothing wrong about that, it is just not what you want  
  
  ---
  
  