I came up with a solution.  In the baked Controller for the market, I
took a look at the $this variable after this line:
$this->set('market',' $this->Market->read(null, $id));

One of the pieces of $this was an array called viewVars which is
passed to the view.

In that arra were a bunch of ['Stations'] that had the fields from the
station database.  But it didn't have any associated models underneath
that.

So I added this:
                for ($i = 0; $i < count($this->viewVars['market']
['Station']); $i++) {
                        $this->viewVars['market']['Station'][$i] =
$this->Market->Station->findById($this->viewVars['market']['Station']
[$i]['id']);
                }

That replaced the information sent about the stations with information
that is returned by the Station model.

Then, in the view, for the related station section, a line like this:
echo $station['id'] is changed to:
echo $station['Station']['id']

That change is done so that your information that was already printing
out still prints out.  Furthermore, I wanted to change foreign keys so
a line like this:
echo $station['market_id'] is changed to:
echo $station['Market']['name']

the $station array used to look like this:
Array
(
    [id] => 849
    [market_id] => 556
    [name] => WRIC
    [affiliation_id] => 1
)

Now it looks like this:
Array
(
    [Station] => Array
        (
            [id] => 849
            [market_id] => 556
            [name] => WRIC
            [affiliation_id] => 1
        )

    [Market] => Array
        (
            [id] => 556
            [name] => RICHMOND-PETERSBURG
            [dmacode] => 556
        )

    [Affiliation] => Array
        (
            [id] => 1
            [name] => ABC
        )

)


So as you can see now the View is getting all of the model logic for
the related models and not just the main one.  I think scaffolding
should be smart enough to do this anyway, but I guess you don't want
to make scaffolding too smart.

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

Reply via email to