Thursday, December 29, 2011

CakePHP and a normalized database

Quick question, I have the following normalized MySQL database with
tables:

Users
- id
- username
- password
- person_id

People
- id
- firstname
- lastname
- address_id
- email_id

Addresses
- id
- address
- city_id
- state_id
- country_id
- zipcode_id

Countries
- id
- country

I have been having problems setting the correct cakephp Model
relations between them. Actually, after reading the documentation I'm
not really sure if it's even possible to have this kind of databas
structure work with cakephp.

So far this is what I have:
Users - belongsTo/hasOne - People (person_id)
People - belongsTo/hasOne - Addresses (address_id)
Addresses - belongsTo/hasOne - Countries (country_id)

So, when I use the User model how can I have cakephp return everything
from the user's firstname, lastname, to the address including country
and states?
To make matters more difficult, how can I have cakePHP (using the
FormHelper) insert an user account that has the firstname and lastname
(this I already got working), and also the address, city, state and
country (this I can't figure it out)?

My issue is that the Countries table for example is related to the
Address table but not to the People table directly nor the Users table
directly.

Any help or guidance would be truly appreciated.

Thanks in advance.

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: