2

I am trying to practice the section of Saving BelongsToMany Associations where an example given in the document is to make an association between two existing entities.

I followed below examples in my ArticlesController.php

    $this->loadModel('Users');

    $article = $this->Articles->get(2);
    $user = $this->Users->get(1);

    $links = $this->Articles->Users->link($article, [$user]);

    debug($links);

Note: I am getting the values correctly from $article and $user Variables

after debugging this, i am getting the errors which is 'Unknown method "link" ' where there is no clue from where the link method comes here in the document. the errors result from ArticlesController

Thanks in advance for helping & guiding me.

ndm
  • 59,784
  • 9
  • 71
  • 110
Bayezid Alam
  • 270
  • 5
  • 17
  • 2
    `$this->Articles->Users` is probably not an instance of `\Cake\ORM\Association\BelongsToMany`. – ndm Feb 08 '18 at 10:21
  • Thanks a lot @ndm, it seems the BelongsToMany Association were not set. Now it is working. But it should have a clue when an error is raised – Bayezid Alam Feb 11 '18 at 05:37

0 Answers0