after create a many to many (HABTM) relationship between 2 classes (as code bellow) I was expecting to see results including the related records but for some reason this is not happening.
Models
App::uses('AppModel', 'Model');
class NewsCategory extends AppModel{
public $hasAndBelongsToMany = array('News');
}
App::uses('AppModel', 'Model');
class News extends AppModel{
public $hasAndBelongsToMany = array('NewsCategory');
}
I created a table called "news_news_categories" with both tables id.
Controller
this->data = $this->News->find('first', array('conditions' => array('News.id' => $id)));
The result from code above doesn't include the related NewsCategory records.
After spend hours trying to make this happen, I couldn't get this done.
What I'm missing here?
Thank you all in advance!
Update
When I dump the SQL code used by CakePHP using
echo $this->element('sql_dump');
the results didn't show any query (or joining) for this relationship. CakePHP is simply ignoring the $hasAndBelongsToMany config.