Well that's what I would have expected and is how I set it up to begin
with, but it didn't seem to work that way. I had my tables and
associations built exactly as you describe in your second example, but
when I called up a record from the Products model, it found no related
Image, because it seemed to be expecting the presence of a product_id
foreign key in the image table. The manual demonstrates the hasOne
relationship with Users and Profiles, and it would appear that if a
User hasOne Profile, the foreign key should be user_id in the profiles
table.
<?php
class User extends AppModel
{
var $name = 'User';
var $hasOne = array('Profile' =>
array('className' => 'Profile',
'conditions' => '',
'order' => '',
'dependent' => true,
'foreignKey' => 'user_id'
)
);
}
?>
The manual then says "Now, when we execute find() or findAll() calls
using the Profile model, we should see our associated User model there
as well". The example it shows is not a find() on the Profile model
but the User model, and it clearly is looking for the user_id in the
profile table.
$user = $this->User->read(null, '25');
print_r($user);
//output:
Array
(
[User] => Array
(
[id] => 25
[first_name] => John
[last_name] => Anderson
[username] => psychic
[password] => c4k3roxx
)
[Profile] => Array
(
[id] => 4
[name] => Cool Blue
[header_color] => aquamarine
[user_id] = 25
)
)
If I have some missunderstanding of how associations are supposed to
work, I'd like to get that cleared up, but as it stands I have an
image_id in my products table and an association of Products belongsTo
Image and it works. I call up a Product and get the associated image
data. It doesn't make 'sense' but it works.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---