Now i can read the model and i get the relation, but when i try to
save a new one, it saves the first model, but it doesn't save the
relation table. Instead it makes a delete:
1 INSERT INTO `rate_requests` (`user_id`) VALUES (4)
2 SELECT LAST_INSERT_ID() AS insertID
3 DELETE FROM `media_rate_requests` WHERE `rate_request_id` = '10'
4 SELECT `RateRequest`.`id`, `RateRequest`.`user_id`,
`RateRequest`.`name`, `RateRequest`.`description` FROM `rate_requests`
AS `RateRequest` WHERE `RateRequest`.`id` = 10 LIMIT 1
5 SELECT `Media`.`id`, `Media`.`name`, `Media`.`description`,
`Media`.`link`, `Media`.`user_id`, `Media`.`category_id`,
`Media`.`created`, `Media`.`modified` FROM `media` AS `Media` JOIN
`media_rate_requests` ON (`media_rate_requests`.`rate_request_id` = 10
AND `media_rate_requests`.`media_id` = `Media`.`id`) WHERE 1 = 1
That's the debugging trace. My code is:
$this->data['Media']['Media'] = 15;
$this->data['RateRequest']['user_id'] = 2;
$this->RateRequest->save($save);
$this->data = $this->RateRequest->read();
in the view i pr $this->data:
<?php pr($this->data); ?>
and i get:
Array
(
[RateRequest] => Array
(
[id] => 10
[user_id] => 4
[name] =>
[description] =>
)
[Media] => Array
(
)
)
What can be wrong??? i've spent like 5 hours googling and i can't get
anything!
Thanks
On 10 sep, 12:12, "Samuel DeVore" <[EMAIL PROTECTED]> wrote:
> table name is plural
> medias_rate_requests
>
> On 9/10/07, Sebastian Choren <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi. I've got 2 models, n<->m, and i'm trying to asociate them with HABTM, so
> > i wrote this code:
>
> > <?php
> > class Media extends AppModel {
> > var $name = 'Media';
> > var $belongsTo = array('MediaCategory' => array(
> > 'foreignKey' => 'category_id'
> > )
> > );
> > var $hasOneAndBelongsToMany = array('RateRequest');
> > }
> > ?>
>
> > <?php
> > class RateRequests extends AppModel {
> > var $name = 'RateRequests';
> > var $hasOneAndBelongsToMany = array('Media');
> > }
> > ?>
>
> > I don't get any error, so i think there's no mistake. I've used all cake
> > conventions in the db naming (tables, fields, etc).
>
> > i've got an intermediate table (called 'media_rate_request'). I don't have a
> > model for this table, but as far as i know from reading in this group and in
> > the bakery, i think that model isn't necessary.
>
> > My problem is that when an action calls for example $this->Media->findAll();
> > i get the first associated table, but i don't get anything from the HABTM
> > relation. Why am i having this problem????
>
> > Thank you!!!
>
> --
> (the old fart) the advice is free, the lack of crankiness will cost you
>
> - its a fine line between a real question and an idiot
>
> http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---