OK,
Getting a little way closer, I've found this article here
http://jbenner.net/blog/understanding-cakephp-associations that
mirrors what it says on the php site under here :
http://book.cakephp.org/view/78/Associations-Linking-Models-Together
What I have at present is a model called personsaddress.php which
contains this code:
<?php
class PersonsAddress extends AppModel {
var $name = 'PersonsAddress';
var $hasAndBelongsToMany = array(
'addresses' =>
array(
'className' => 'address',
'joinTable' => 'persons_addresses',
'foreignKey' => 'name_id',
'associationForeignKey' => 'addr_id',
'unique' => true
)
);
}
?>
and on the fullnames_controller.php I have this function:
function view($id = null) {
$this->Fullname->id = $id;
$this->set('fullname', $this->Fullname->read());
$this->set('linkaddr', $this->Addresses->read(null, $id));
}
I'm assuming that linkaddr should hold an array with the users
addressdetails, calling view.cpt but I'm getting the error:
Notice (8): Undefined property: FullnamesController::$Addresses [APP/
controllers/fullnames_controller.php, line 10]
Fatal error: Call to a member function read() on a non-object in
<path>/controllers/fullnames_controller.php on line 10
Would be grateful for some pointers?
Thanks
Darren
On Sep 11, 3:43 pm, Whitty <[email protected]> wrote:
> Hi,
>
> I'm a bit new to this, I'm trying to do a left join.
>
> I have a db with People table (id:name_id) in it a linking table
> (linking name_id to addr_id) and an address table with the index
> (addr_id)
>
> the sql command I usually use is:
>
> SELECT persons_address.addr_id FROM addresses left JOIN
> persons_address ON persons_address.addr_id = addresses.addr_id WHERE
> persons_address.name_id ='.$name_id
>
> I'm assuming I need a model for the linking table.
>
> How would I go about creating a query to print out the users name with
> the linked address below? I've got as far as outputting the user name.
>
> Are their any examples?
>
> Darren
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---