I have a table
Medias:
ID,
PARENT_ID
PATH
TITLE
Items:
ID
medias
Title
description
Models
class ImageGallery extends AppModel {
public $name = 'ImageGallery';
public $useTable = "medias";
var $belongsTo = array(
'Parent' =>
array('className' => 'ImageGallery',
'foreignKey' => 'parent_id',
'dependent' => false,
),
);
var $hasMany = array(
'Children' =>
array('className' => 'ImageGallery',
'foreignKey' => 'parent_id',
'dependent' => false,
),
);
}
class Item extends AppModel {
public $useTable = "items";
public $validate = array(
'title' => array(
'rule' => 'notEmpty'
),
);
public $belongsTo = array(
'Gallery' => array(
'className' => 'ImageGallery',
'foreignKey' => 'medias'),
);
public $hasMany = array(
'ItemMeta' => array( 'className' => 'ItemMeta'),
);
}
The media table contains gallery information. Images are stored in parent_id relation.
When I request Item->find('all');
I am getting only one entry from Media table, but I want to get all its children too. :(
I can get its children by using $this->ImageGallery->findById(10);
, but I want to get them with the Item Model.