Try playing with the 'recursive' param:

$data = $this->Port->find(
        'first',
        array(
                'fields' => array('*'),
                'recursive' => 2
        )
);

$this->set(compact('data'));

Alternatively, if you are using ContainableBehavior (I recommend
setting AppModel to use it so it's always available) you can do this:

$data = $this->Port->find(
        'first',
        array(
                'fields' => array('*'),
                'contain' => array(
                        'HardwareUnit',
                        'PortUplink'
                )
        )
);

To see the data array:

die(debug($data));

I just noticed that you named your variable $ports, not $data. Adjust
as necessary.

On Mar 22, 7:53 am, sebb86 <kahlc...@googlemail.com> wrote:
> Hello,
> I'd like to show the following things in my view (respectively in the
> field uplink_id in the view): attribute "uplink_id" from table "ports"
> with attribute "schenker_number" from table "hardware_units".
> My problem are the associations, respectively i don't know the source
> code to retrieve the information i want.
>
> Fields:
> - "id" (table "ports" = primary-key)
> - "hardware_unit_id" (table "ports", = foreign-key associated with
> "id" from table "hardware_units")
> - "id" (table "hardware_units" = primary-key)
> - "uplink_id" (table "ports" = foreign-key associated with "id" from
> table "ports")
>
> Example with values:
> - "id" (table "ports") has value 4
> - "hardware_unit_id" has value 2 ---> "id" (table "hardware_units")
> has also value 2
> - "uplink_id" has value 1 (points to the "id" (table "ports" with
> value 1)
>
> So when i do this:
> {{{
> echo $port['HardwareUnit']['schenker_number'];
>
> }}}
>
> , i get the "schenker_number" from the hardware_unit, which is
> associated with the port ("id" = 4) BUT i need the "schenker_number"
> which matches with the "hardware_unit_id" from the port with "id"
> value 1 because of the "uplink_id" (value 1).
>
> **Model:**
> {{{
> class Port extends AppModel
> {
>   var $name= 'Port';
>
>   public $belongsTo = array(
>         'HardwareUnit' => array(
>         'className'  => 'HardwareUnit'
>          )
>    );
>
>    var $hasOne = array(
>     'PortUplink' => array(
>     'className' => 'Port',
>     'foreignKey' => 'uplink_id'
>     )
>    );
>
> }}}
>
> **Controller:**
> {{{
> class PortsController extends AppController
> {
>         var $name = 'Ports';
>         function index()
>         {
>                 $this->set('ports', $this->Port->find('all'));
>         }
>
> }}}
>
> **View:**
> {{{
> <?php foreach ($ports as $port): ?>
> <td style="text-align:left"><?php echo $port['Port']['uplink_id']; ?></
>
> td>
>
> }}}
>
> Please don't hesitate to ask if i expressed myself unclearly.
> Thanks if someone can help.
> Greetings. :)

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

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