Hello, i'm new both to php and cake, so please excuse me if this is
another obvious noob question.

I was trying to understand how associations work by building up the
example in the manual section of cakephp.org, i was able to build it
up using bake with no much effort.

The thing is, i have a users table and a profiles table, they look
like this:

CREATE TABLE `profiles` (
  `id` int(11) NOT NULL auto_increment,
  `name` varchar(100) collate utf8_unicode_ci NOT NULL,
  `header_color` varchar(100) collate utf8_unicode_ci NOT NULL,
  `user_id` int(11) NOT NULL,
  PRIMARY KEY  (`id`),
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE TABLE `users` (
  `id` int(11) NOT NULL auto_increment,
  `first_name` varchar(100) collate utf8_unicode_ci NOT NULL,
  `last_name` varchar(100) collate utf8_unicode_ci NOT NULL,
  `username` varchar(100) collate utf8_unicode_ci NOT NULL,
  `password` varchar(100) collate utf8_unicode_ci default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

using bake i was able to create the models and to define the following
associations

User:
        var $hasOne = array('Profile' =>array('className' => 'Profile',
                                                'foreignKey' => 'user_id',
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',
                                                'dependent' => ''),);
Profile:
        var $belongsTo = array('User' =>array('className' => 'User',
                                                'foreignKey' => 'user_id',
                                                'conditions' => '',
                                                'fields' => '',
                                                'order' => '',
                                                'counterCache' => ''),);

Which seems good to me, but testing the application i was able to
create a second profile for one user.
I was guessing if the hasOne association should check that and return
an error, or I am missing something?
On the other hand, i builded the tables based on my own understanding
of the example, maybe they are wrong, and so the whole example.

I was thinking of adding an UNIQUE clause on the user_id so forcing
only one profile per user but doing that causes the application to
show an ugly error database message, which is correct and obviously i
can take care of it, but not seems to follow the elegant and simple
rules of the rest of the application.

What also worries me is that in a hasOne association i would expect
the users table to have a foreign key to the profiles table, not the
contrary like in the example.

I see I wrote a quite long message, I believe that giving the max info
possible tends to help answering better responses and keeping threads
short, but if its against forum rules, please let me know.

Thanks in advance

Chus


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

Reply via email to