Hey, im having this issue with cakephp, bascially i have a Has And Belongs To Many (HABTM) model relationship.
My models are Categroy and Project
bring all project data is fine, it comes out as [0]['Project'], [1]['Project'] ...etc
but when i use the relationship and pull out projects with certain categories in the categories controller i get these tpye of results [0] (all project data in [0] instead of [0]['Project']), [1] (project data and related model info) this is really messing my code up as i use one element view file to render my projects is there any way to return [0]['Project'] for both project controller and categories controller? thanks Chris
Your example is a bit hard to understand, but in general it's correct that records of related "-Many" models do not contain the model name in the array. I wouldn't recommend you to attempt to change that, just get used to how Cake fetches results and keep it consistent throughout the app. It's easy enough to make a view element or helper work with either format. Something along the lines of this:
$projects = $category['Project'];
if (isset($projects['Project'])) {
$projects = $projects['Project'];
}
foreach ($projects as $project) {
// treat $project as if it's always a flat array
}
Since I don't really understand your example, you'll have to adapt this a bit, but you get the idea...