OK, so you're trying to save hasMany records each with their own
HABTM, there is no automagic that will do that for you hence why
you've had to try and come up with your own solution.

Are you sure it's not easier to save just one review/serviceType combo
at a time?  By trying to do lots in one go you're also going to have
problems validating your data and displaying errors etc.  You could
create an array of data arrays and loop through them validating and
saving, but even that is a minefield as at what point of validation
fails to you return and what do you do with those records that were
saved.

Any chance of seeing one of your forms in action (I have great
difficulty looking at table schemas and php/html and visualising how
the end product looks), it may give me a better idea of what you're
trying to achieve.

HTH

Paul.

On Mar 22, 6:48 am, jwerd <[email protected]> wrote:
> Paul,
>
> First off, Thanks for taking a look.
>
> I guess I am just confused on how I can go about the associations,
> since my ratings table is storing specific based on the
> editorial_review_id's service_type_id, if that makes sense.
>
> Essentially, someone creates a review, and they drill down with the
> rating criteria of each service, since services will having different
> ratings.  So an example would be:
>
> Parent: Editorial Review
> Child: Service Type: Hosted
> Sub Child: Rating Criteria 1
> Sub Child: Rating Criteria 2
> Sub Child: Rating Criteria 3
> Sub Child: Rating Criteria 4
> Sub Child: Rating Criteria 5
> Sub Child: Rating Criteria 6
> Sub Child: Rating Criteria 7
> Sub Child: Rating Criteria 8
>
> Child: Service Type: VPS
> Sub Child: Rating Criteria 1
> Sub Child: Rating Criteria 2
> Sub Child: Rating Criteria 3
> Sub Child: Rating Criteria 4
> Sub Child: Rating Criteria 5
> Sub Child: Rating Criteria 6
> Sub Child: Rating Criteria 7
> Sub Child: Rating Criteria 8
>
> The reason I'm doing this this way is I want to make this system a bit
> more dynamic, in the sense that a publisher could add more rating
> criterias later on without a bunch of code changes, etc.
>
> So, my reason for massging is, I do not know how I can go about saving
> this later in a way that cake understands it.  I have to set up a
> bunch of hidden id's just so I can bring this data in to save it, eg:
> <?php $i = 0; ?>
> <?php $k = 0; ?>
>
> <div style="clear:both;">
> <?php foreach($this->viewVars['serviceTypes'] as $key => $val): ?>
> <div id="service_type_<?=$key?>" style="display: none;
> position:relative; padding: 5px; background: #ddd; float:left; margin-
> right:4px;">
>         <h3>
>         <?php echo $form->label($val); ?>
>         </h3>
>         <?php $j = 1;?>
>         <?php foreach($ratingTypes as $key2 => $val2): ?>
>         <br />
>         <?php if(!empty($this->data['Rating'][$key][$j]['id'])): ?>
>         <?php echo $form->hidden('', array('name' => 'data[Rating]['.$key.']
> ['.$j.'][id]', 'value'=>@$this->data['Rating'][$key][$j]['id'])); ?>
>         <?php endif; ?>
>         <?php echo $form->hidden('EditorialReviewId', array('name' =>
> 'data[Rating]['.$key.']['.$j.'][editorial_reviews_id]', 'value'=>@
> $this->data['EditorialReview']['id'])); ?>
>         <?php echo $form->hidden('ServiceTypeId', array('name' =>
> 'data[Rating]['.$key.']['.$j.'][service_types_id]', 'value'=>@$key)); ?
>
>         <?php echo $form->hidden('RatingTypeId', array('name' => 'data[Rating]
> ['.$key.']['.$j.'][rating_types_id]', 'value'=>@$key2)); ?>
>         <?php
>                 $select = (isset($this->data['Rating'][$key][$j]['rating'])) 
> ? $this->data['Rating'][$key][$j]['rating'] : 1;
>
>         ?>
>         <div style="padding: 5px; margin-bottom: 0px; background: #ccc;
> display: inline; width:220px; float:left;">
>         <?php
>                 echo $form->label($val2);
>         ?>
>         </div>
>         <div style="margin-bottom: 0px; padding: 5px; display: inline;">
>         <?php
>                 echo $form->select('', array('1'=>'1 - Very
> Poor','2'=>'2','3'=>'3','4'=>'4','5'=>'5 - Average', '6'=>'6',
> '7'=>'7', '8'=>'8', '9'=>'9', '10'=>'10 - Excellent'), @$select,
> array('style'=>'position:relative; top:2px;','name'=> 'data[Rating]['.
> $key.']['.$j.'][rating]'), false);
>                 unset($select);
>         ?>
>         </div>
>         <div style="clear:both;"></div>
>         <?php ++$j; ?>
>         <?php ++$k; ?>
>         <?php endforeach; ?>
>
> There has to be an easier way than this convoluted system.  There is
> also a bug with this, doing it this way, I have to have the record
> created so I can associate the editorial_review_id with the ratings.
>
> TIA
>
> On Mar 21, 1:45 am, WebbedIT <[email protected]> wrote:
>
> > I'm slightly confused, why do you have to massage the data array?
> > What part of your save process is not working, I'm guessing your
> > saying it is not autosaving the HABTM data.
>
> > If so, what does your submitted data array and save action look like?
>
> > HTH
>
> > Paul

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 [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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to