Update relational models

I have 3 related tables

Articles(id, title, ...)

Categories(id, name),

Articles_Categories(artilceId, categoryId)

When I do an update to the categories of one of my Articles, like this:

$article = Articles::findFirst();
//Adding new category e.g
$categories[] = Categories::findFirst();

$article->categories = $categories;

the new associations are not added the the Articles_Categories

Here is my defined relationships:

class Articles extends Model{
    public function initialize(){
        $this->belongsTo("Redacteurs_id", 'AutoPoster\Backend\Models\Users', "id", array(
            'alias' => 'user'

        /*$this->hasMany("id", 'AutoPoster\Backend\Models\ArticlesHasCategories', "articleId", array(
            'alias' => 'categories'
            'articleId', 'categoryId',
                'alias' => 'categories',
                'foreignKey' => array(
                    'action' => Model\Relation::ACTION_CASCADE



HI I think problem in above.

    $categories[] = Categories::findFirst();

    $article->categories = $categories;


How to fix it ?