Answers.Body: <p>In the super table array, there has to be a type there:</p>
  
  <pre><code>"superTableHandle" =&gt; array:5 [
      0 =&gt; array:3 [
        "type" =&gt; 1//the field's id
        "fields" =&gt; array:10 [
          "relatedArticle" =&gt; 325051
          ...
        ]
      ]
      1 =&gt; [...]
  </code></pre>
  
  <p>For me, this id is 1. It can be found in database by running this SQL</p>
  
  <pre><code>select * from supertableblocktypes;
  </code></pre>
  
  <p>But I ran the code below before and found out the field's id is 81 which is not working for me, I don't know why</p>
  
  <pre><code>dd(Craft::$app-&gt;fields-&gt;getFieldByHandle('matrixHandle')-&gt;blockTypeFields);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-04T04:16:22.160Z
Answers.LastActivityDate: 2018-07-04T04:16:22.160Z
Answers.UserDisplayName: yu xia
Body: <p>I have an entry with a Matrix field, inside this field I have a Super Table as block type.  My fields data looks like below:</p>
  
  <pre><code>"title" =&gt; "test1"
  "matrixHandle" =&gt; array:2 [
    0 =&gt; array:2 [
      "type" =&gt; "sponsorshipRow"
      "fields" =&gt; array:2 [
        "sectionTitle" =&gt; "blablabla"
        "superTableHandle" =&gt; array:5 [
          0 =&gt; array:3 [
            "fields" =&gt; array:10 [
              "relatedArticle" =&gt; 325051
              ...
            ]
          ]
          1 =&gt; [...]
    1 =&gt; [...]
  </code></pre>
  
  <p>Then I loop these fields</p>
  
  <pre><code>foreach ($fields as $key =&gt; $value) {
      $entry-&gt;setFieldValue($key, $value);
  }
  </code></pre>
  
  <p>And last, I save the entry:</p>
  
  <pre><code>Craft::$app-&gt;elements-&gt;saveElement($entry);
  </code></pre>
  
  <p>But every data is saved except for the super table block. The super table block is not even created. Any idea please?</p>
  
Tags: <plugin-development><plugin-supertable>
Title: How to save a Matrix with Super Table in it
ThreadText: # How to save a Matrix with Super Table in it
  
  (Asked by: username_0 on 2018-07-04)
  
  I have an entry with a Matrix field, inside this field I have a Super Table as block type. My fields data looks like below:
  
  ```
  "title" => "test1"
  "matrixHandle" => array:2 [
    0 => array:2 [
      "type" => "sponsorshipRow"
      "fields" => array:2 [
        "sectionTitle" => "blablabla"
        "superTableHandle" => array:5 [
          0 => array:3 [
            "fields" => array:10 [
              "relatedArticle" => 325051
              ...
            ]
          ]
          1 => [...]
    1 => [...]
  
  ```
  
  Then I loop these fields
  
  ```
  foreach ($fields as $key => $value) {
      $entry->setFieldValue($key, $value);
  }
  
  ```
  
  And last, I save the entry:
  
  ```
  Craft::$app->elements->saveElement($entry);
  
  ```
  
  But every data is saved except for the super table block. The super table block is not even created. Any idea please?
  
  **Tags:** plugin-development, plugin-supertable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-07-04. Score: 1 | Accepted answer
  
  In the super table array, there has to be a type there:
  
  ```
  "superTableHandle" => array:5 [
      0 => array:3 [
        "type" => 1//the field's id
        "fields" => array:10 [
          "relatedArticle" => 325051
          ...
        ]
      ]
      1 => [...]
  
  ```
  
  For me, this id is 1. It can be found in database by running this SQL
  
  ```
  select * from supertableblocktypes;
  
  ```
  
  But I ran the code below before and found out the field's id is 81 which is not working for me, I don't know why
  
  ```
  dd(Craft::$app->fields->getFieldByHandle('matrixHandle')->blockTypeFields);
  
  ```
  
  
  ---
  
  