Thursday, March 25, 2010

Re: retrieve related model data

sure! :-)

[code of model port]
public $belongsTo = array(
'HardwareUnit' => array(
'className' => 'HardwareUnit'
),
'Vlan' => array(
'className' => 'Vlan'
),
'PortEmploymentGroup' => array(
'className' => 'PortEmploymentGroup'
)
);

public $hasAndBelongsToMany = array(
'MacAddress' => array(
'className' => 'MacAddress',
'joinTable' => 'mac_addresses_ports',
'foreignKey' => 'port_id',
'associationForeignKey' => 'mac_address_id',
'unique' => true
)
);

public $hasMany = array(
'Port' => array(
'className' => 'Port',
'foreignKey' => 'uplink_id'
)
);
[/code]


Is that, what you want, when you ask to see the find statement? ->
[controller code]
var $paginate = array(
'fields' => array('*'),
'recursive' => 2,
'limit' => 50,
'order' => array('Port.hardware_unit_id' => 'asc'),
'contain' => array(
'Port' =>
array('HardwareUnit'),'HardwareUnit','Vlan','PortEmploymentGroup')
);

....

function view()
{
$this->set('ports', $this->paginate('Port'));
}
[/code]

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+unsubscribe@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.

No comments: