OK, again thanks for your help.

So I have the ID being passed back as a hidden field:
echo $form->input('id', array('type'=>'hidden', 'value' =>
$rental['Rental']['id'])); 

I thought that Cake would, due to the relationship I set up in the Model,
grab the ID from Rental and pass it to Rate as rental_id. Is this not the
case? Do I need to explicitly set rental_id such as:

$this->data['Rate']['rental_id'] = $this->data['Rental']['id'] ??



John Andersen-6 wrote:
> 
> If you are editing an existing record, then your data must include the
> id, so that the model knows that it is an existing record and not a
> new one. If the id is not present, then the model will create a new
> record.
> 
> So your data array for the Rate should also include the id, like this:
> 
> [code]
> 
>     [Rate] => Array
>         (
>             [id] => 8
>             [s1_title] => s1 Title
>             [s1_day] =>
>             [s1_week] =>
>             [s1_month] =>
>             [s2_title] =>
> ...
> [/code]
> 
> Your edit form should ensure this (hidden field) or someway else.
> Enjoy,
>    John
> 
> On Jan 15, 10:16 pm, koala kid <a...@koalawebsolutions.com> wrote:
>> I definitely have something funny going on with these associations, I
>> just
>> noticed that when I do an update on the Rentals, it creates a NEW entry
>> in
>> the Rate table rather than updating the entry with the correct ID.
>>
>> Boy this ORM stuff just confuses the hell out of me.
>>
>>
>>
>> koala kid wrote:
>>
>> > I already fixed that at some point whilst looking for the problem. My
>> > classes now look like this:
>>
>> > class Location extends AppModel
>> > {
>> >    var $name = 'Location';
>> >     var $hasMany = array(
>> >         'Rental' => array(
>> >             'className'  => 'Rental',
>> >             'order'      => 'Rental.created DESC'
>> >         )
>> >     );
>>
>> > class Rental extends AppModel
>> > {
>> >    var $name = 'Rental';
>>
>> >    var $hasOne = array(
>> >         'Rate' => array(
>> >             'className'    => 'Rate',
>> >                    'foreignKey'   => 'rental_id',
>> >             'dependent'    => true
>> >         )
>> >     );
>> >    var $belongsTo = array(
>> >         'Location' => array(
>> >             'className'            => 'Location'
>> >         )
>> >     );  
>> > }
>>
>> > class Rate extends AppModel
>> > {
>> >    var $name = 'Rate';
>>
>> >    var $belongsTo = array(
>> >         'Rental' => array(
>> >             'className'            => 'Rental'
>> >         )
>> >     );    
>>
>> > }
>>
>> > Thanks.
>>
>> > John Andersen-6 wrote:
>>
>> >> You probably get the warning due to the following:
>>
>> >> [code]
>> >> class Rate extends AppModel
>> >> {
>> >>        var $name = 'Rate';
>> >>        var $belongsTo = 'Rentals';
>> >> }
>> >> [/code]
>>
>> >> Observe that you have given your Rental model as Rentals in the
>> >> belongsTo association! Fix that and the warning should go away. Enjoy,
>> >>    John
>>
>> >> On Jan 15, 9:34 pm, koala kid <a...@koalawebsolutions.com> wrote:
>> >>> Thanks, that fixed it. For some reason I had Rate/ instead of Rate.
>> in
>> >>> my
>> >>> HTML form as the input name, changing that and its now saving. Thanks
>> >>> for
>> >>> the tip.
>>
>> >>> However I've now got another issue! When I submit the form the data
>> is
>> >>> being
>> >>> saved but I get a PHP warning:
>>
>> >>> Warning (2): Illegal offset type in unset
>> >>> [CORE/cake/libs/model/model.php,
>> >>> line 561]
>>
>> >>> Code | Context
>>
>> >>> $params =       array(
>> >>>         "belongsTo" => array(
>> >>>         "Location" => array()
>> >>> )
>> >>> )
>> >>> $reset  =       true
>> >>> $models =       array(
>> >>>         "Location" => array(
>> >>>         "className" => "Location"
>> >>> )
>> >>> )
>> >>> $assoc  =       "belongsTo"
>> >>> $model  =       array(
>> >>>         "className" => "Location"
>> >>> )
>>
>> >>>             foreach ($models as $model) {
>> >>>                 $this->__backAssociation =
>> >>> array_merge($this->__backAssociation, $this->{$assoc});
>> >>>                 unset ($this->__backAssociation[$model]);
>>
>> >>> Model::unbindModel() - CORE/cake/libs/model/model.php, line 561
>> >>> RentalsController::edit() - APP/controllers/rentals_controller.php,
>> line
>> >>> 91
>> >>> Object::dispatchMethod() - CORE/cake/libs/object.php, line 116
>> >>> Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 227
>> >>> Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 194
>> >>> [main] - APP/webroot/index.php, line 88
>>
>> >>> It looks like I still haven't got my head around this ORM thing. Have
>> I
>> >>> set
>> >>> up my associations correctly?
>>
>> >>> Thanks for your help.
>>
>> >> [snip]
>>
>> >> Check out the new CakePHP Questions sitehttp://cakeqs.organd help
>> >> others with their CakePHP related questions.
>>
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "CakePHP" group.
>> >> To post to this group, send email to cake-php@googlegroups.com
>> >> To unsubscribe from this group, send email to
>> >> cake-php+unsubscr...@googlegroups.com For more options, visit this
>> group
>> >> athttp://groups.google.com/group/cake-php?hl=en
>>
>> --
>> View this message in
>> context:http://old.nabble.com/Unable-to-save-related-table-information-tp2715...
>> Sent from the CakePHP mailing list archive at Nabble.com.
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php?hl=en
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Unable-to-save-related-table-information-tp27153345p27184576.html
Sent from the CakePHP mailing list archive at Nabble.com.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to