<p>Turns out this <em>was</em> a bug in Craft and we've just fixed it for the next (post build 2568) release.</p>

CC BY-SA 3.0
2014-08-15T19:19:30.613Z
2014-08-15T19:19:30.613Z
Brad Bell
<p>One of the functions in a plugin that I'm working on, is the ability to create fields. It has created a Matrix field, and directly after that, I want to know the MatrixBlockType.</p>

<p>I don't get any results if I use the following code:</p>

<pre class="lang-php prettyprint-override"><code>$blockTypes = craft()&gt;matrix&gt;getBlockTypesByFieldId($newField-&gt;id, 'handle');
</code></pre>

<p>However, if I do the exact same thing as the above function should do, and run this code I do have results:</p>

<pre class="lang-php prettyprint-override"><code>$results = craft()-&gt;db-&gt;createCommand()
-&gt;select('id, fieldId, fieldLayoutId, name, handle, sortOrder')
-&gt;from('matrixblocktypes')
-&gt;where('fieldId = :fieldId', array(':fieldId' =&gt; $newField&gt;id))
-&gt;order('sortOrder')
-&gt;queryAll();
</code></pre>

<p>If you would debug both variables, you'll notice that the first one doesn't contain any data.</p>

<p>If I would be creating the fields and in later server request I would use the first example, I do receive the data. Somehow it's not available right after creating the field.</p>

<p>Can anyone help me out here by any chance? I want to use the first example, which is the correct way.</p>

CC BY-SA 3.0
2014-07-06T11:46:53.023Z
This looks like a bug. Try sending a mail to support@buildwithcraft.com and update this question if you can solve your problem. :)
Victor
CC BY-SA 3.0
2014-07-13T00:48:24.970Z
Why aren't there any dashes/hyphens before the greater-than signs in your first code example?
Tyler Willingham
CC BY-SA 3.0
2014-07-13T21:40:34.993Z
@Hubert Have you made any progress with this? Curious whether it ended up being a bug.
Matt Stein
CC BY-SA 3.0
2014-07-14T06:07:30.577Z
@Willingham I posted this on Google plus first. Apparently it removes the dashes.
Hubert
CC BY-SA 3.0
2014-07-14T06:10:21.383Z
@Matt No progress yet. Picked it up with Brad, so i'll update this when I know more.
Hubert
CC BY-SA 3.0
2014-07-18T01:43:22.383Z
@Hubert Replied to your ticket on the 9th and haven't heard back, just in case you didn't receive it.
Brad Bell
<plugin-development><matrix>
Matrix getBlockTypesByFieldId() function doesn't work as intended?
# Matrix getBlockTypesByFieldId() function doesn't work as intended?

(Asked by: username_0 on 2014-07-04)

One of the functions in a plugin that I'm working on, is the ability to create fields. It has created a Matrix field, and directly after that, I want to know the MatrixBlockType.
I don't get any results if I use the following code:
$blockTypes = craft()>matrix>getBlockTypesByFieldId($newField->id, 'handle');

However, if I do the exact same thing as the above function should do, and run this code I do have results:
$results = craft()->db->createCommand()
->select('id, fieldId, fieldLayoutId, name, handle, sortOrder')
->from('matrixblocktypes')
->where('fieldId = :fieldId', array(':fieldId' => $newField>id))
->order('sortOrder')
->queryAll();

If you would debug both variables, you'll notice that the first one doesn't contain any data.
If I would be creating the fields and in later server request I would use the first example, I do receive the data. Somehow it's not available right after creating the field.
Can anyone help me out here by any chance? I want to use the first example, which is the correct way.

**Tags:** plugin-development, matrix
> **Comments:**
> **username_1**: This looks like a bug. Try sending a mail to support@buildwithcraft.com and update this question if you can solve your problem. :)  
> **username_2**: Why aren't there any dashes/hyphens before the greater-than signs in your first code example?  
> **username_3**: @Hubert Have you made any progress with this? Curious whether it ended up being a bug.  
> **username_0**: @Willingham I posted this on Google plus first. Apparently it removes the dashes.  
> **username_0**: @Matt No progress yet. Picked it up with Brad, so i'll update this when I know more.  
> **username_4**: @Hubert Replied to your ticket on the 9th and haven't heard back, just in case you didn't receive it.  

---

## 1 answers

### Answer by username_4 on 2014-08-15. Score: 3

Turns out this *was* a bug in Craft and we've just fixed it for the next (post build 2568) release.


---

