Saving related entry in a Matrix block programmaticially I'm trying to add entries to a Matrix block with one field type of 'entry' using the following:

$block = new MatrixBlockModel();
$block-&gt;fieldId    = 9;             // Matrix field's ID
$block-&gt;ownerId    = $collectionID; // ID of entry the block should be added to
$block-&gt;typeId     = 2;             // ID of block type
$block-&gt;getContent()-&gt;setAttributes(array(
    'contentRss' =&gt; array($entry-&gt;id)
));

$success = craft()-&gt;matrix-&gt;saveBlock($block);


The code saves the new block and entry, but when I view the entry it has not linked the entry. I notice in the database tables it has not created an entry in the craft_relations table.

Where am I going wrong? :)
Possibly a duplicate of this one here but hey, here is where I think you are going wrong:

Change this part:

$block-&gt;getContent()-&gt;setAttributes(array(
  'contentRss' =&gt; array($entry-&gt;id)
));


To this:

$block-&gt;getContent()-&gt;contentRss = array($entry-&gt;id);