I have been racking my brains for a few days on this, I am new to cake
and have been building an experimental application, trying to use as
much of the cake functionality as possible to learn it.
Using cake 1.2
The issue I am having is, I cannot not insert/update to a lookup table
from a HABTM association.
I have an artist(s) controller and model and a genre(s) controller and
model.
When I add a new artist to the database I grab the last id inserted
and the genre id from the post array and try to insert it into the
artists_genres table under the artists_id and genres_id columns, I
have tried this a multitude of ways from afterSave to doing it right
in the controller add() function, but to no avail I have not been able
to get it right.
this is my add function from my Artists controller with the suspect
code
function add()
{
$this->set("genreList",$this->Genre->generateList(null, 'name
ASC',
null, '{n}.Genre.id','{n}.Genre.name'));
if (!empty($this->data['Artist']))
{
$this->Artist->create();
$result = $this->Artist->save($this->data['Artist']);
//get last id
$last_id = $this->Artist->getLastInsertId();
//get genre id
$genre_id = $this->data['Artist']['genre_id'];
//insert into lookup table
//I know bad coding; should use save()
$this->query("INSERT INTO artists_genres (artists_id,
genres_id)
VALUES ('". $last_id."','".$genre_id."') ");
if($result){
$this->flash('Your artist has been
added.','/artists/view/'.
$last_id,'3');
}
}
}
As you can suspect I get: Fatal error: Call to undefined method
ArtistsController::query() in C:\AppServ\www\bakemeagig\app\controllers
\artists_controller.php on line 54
Like i said I have tried this in the Artist model as well as a
beforeSave(), but I couldn't figure out how to carry the variables
over to the model to insert them.
This is like the last piece of the puzzle for me. I feel once I figure
this out I'll have a pretty good grasp of cake and be able to advance
to more complex apps.
Any help with this will be truly appreciated, like I said this is like
the last piece of a puzzle that once I see it and understand it I'll
be on my way.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---