Hey all,
I have a n...n
structure for two tables, makes
and models
. So far no problem.
In a third table (products
) like:
id
make_id
model_id
...
My problem is creating a view for products of one specifi make
inside my ProductsController
containing just that's make models:
I thought this could work:
var $uses = array('Make', 'Model');
$this->Make->id = 5; // My Make
$this->Make->find(); // Returns only the make I want with it's Models (HABTM)
$this->Model->find('list'); // Returns ALL models
$this->Make->Model->find('list'); // Returns ALL models
So, If I want to use the list
to pass to my view to create radio buttons I will have to do a foreach()
in my make
array to find all models titles and create a new array and send to the view via $this->set()
.
$makeArray = $this->Make->find();
foreach ($makeArray['Model'] as $model) {
$modelList[] = $model['title'];
}
$this->set('models', $models)
Is there any easier way to get that list without stressing the make
Array. It will be a commom task to develops such scenarios in my application(s).
Thanks in advance for any hint!