Monday, July 5, 2010

Re: Database Design Question

On Mon, Jul 5, 2010 at 10:17 AM, duderion <adrian.gier@googlemail.com> wrote:
> Hi Guys
>
> i have a question about cake compatible database design:
>
> i have a table "mails" and a table "users"
>
> my table mail references 2 users from the users-table as Sender,
> Recipient
>
> but then, i have 2 foreign keys in it, and i dont know how to handle
> this properly
> (or even name it correctly)
>
> Anyone having an idea ? Or do i need a third table with the user,user-
>>mail information...

mails table:

id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
sender_id INT(10) UNSIGNED NOT NULL,
recipient_id INT(10) UNSIGNED NOT NULL,
FOREIGN KEY (sender_id) REFERENCES users (id) ON DELETE CASCADE,
FOREIGN KEY (recipient_id) REFERENCES users (id) ON DELETE CASCADE

User model:

var $hasMany = array(
'MailSender' => array (
'className' => 'Mail',
'foreignKey' => 'sender_id',
'dependent' => true
),
'MailRecipient' => array (
'className' => 'Mail',
'foreignKey' => 'recipient_id',
'dependent' => true
)
);

Then you can refer to each model by its alias, MailSender or MailRecipient.

Note that this does not take into account the situation where a mail
has two or more recipients.

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

No comments: