Its okay - I had coded the $belongsTo and $hasMany a bit strangely:
class ToolCategory extends AppModel {
var $name = "ToolCategory";
var $hasMany = array
(
'Tool' =>
array
(
'className' => 'Tool',
'foreignKey'
=> 'catID',
'dependent'
=> true,
'exclusive'
=> true,
)
);
function index() {
$this->data = $this->ToolCategory->findAll();
}
}
And:
class Tool extends AppModel
{
var $name = "Tool";
var $belongsTo = array
(
'ToolCategory' =>
array
(
'className' => 'ToolCategory',
'conditions' => '',
'order' => '',
'foreignKey' => 'catID'
)
);
function index() {
$this->data = $this->Tool->findAll();
}
}
Thanks anyway :)
On 26 Feb, 10:10, "voycey" <[EMAIL PROTECTED]> wrote:
> Okay - Not sure if the subject made any sense but here is basically
> what I want to do:
>
> I have a table called tools:
> id, created, modified,title,doctype,document,catID
>
> and I have a category table (tool_categories):
> id, created, modified, title
>
> Now in the view for the tools page I want to pull out a category and
> then list under it every tool with a matching CatID.
>
> Do I need 2 seperate models for this?
>
> the kind of thing that I was looking at doing was something like:
>
> class Tool extends AppModel
> {
> var $name = "Tool";
> var $uses = array('ToolCategories','Tools');
>
> var $belongsTo = array(
> 'ToolCategory' => array(
> 'classname' => 'ToolCategory')
> );
>
> function index() {
> $this->data = $this->Tool->findAll() &
> $this->ToolCategory->findAll();
>
> }
>
> }
>
> "$this->data = $this->Tool->findAll() & $this->ToolCategory->findAll();" - im
> not sure whether that would work - but I am
>
> basically trying to pull out the categories and the tool details and
> append them onto the data array.
>
> Any hints on the best way to do this?
>
> Cheers
>
> Dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---