Hi all,
Firstly, I do understand HABTM relationships, having come from a Rails
background and having built sites with these kind of relationships.
What I'm struggling with is the CakePHP way of accessing and creating
relationships.
I have two models, Member and County, and have created a
counties_members join table.
My counties table is populated with data and is simply structured like
id, name. I also have a number of member records in my database. What
I'm trying to do is associate and establish a Member relationship with
zero, one or more Counties.
I am looping through an array which contains county IDs that I know
the Member will have. I've tried a number of different approaches and
am now trying to fill the counties_members table with IDs and have
written this code.
$county_insert = array();
foreach($county_records as $county)
{
$county_insert['CountiesMember']['county_id'] = $county['County']
['id'];
$county_insert['CountiesMember']['member_id'] = $this->Member->id;
$this->Member->CountiesMember->bindModel(array('belongsTo' => array
('County')));
$this->CountiesMember->create();
$this->CountiesMember->save($county_insert);
unset($count_insert);
}
The error I'm getting is:
Undefined property: MembersController::$CountiesMember [APP/
controllers/members_controller.php, line 175]
Fatal error: Call to a member function create() on a non-object in /
www/landscaper.org.uk/app/controllers/members_controller.php on line
175
If anyone has a solution to my HABTM problem, that would be fantastic!
If there is a better way of doing this, then by all means please
enlighten me!
Many thanks in advance,
Alastair
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---