> Hi!
> Im in quite a fix.
> I have created 2 tables as of now
> users
> username,id,password,name,type(owner/incharge/both),email
> Primary key -> id
> equipment
> type,equipmentno,owner,incharge,dateofpurchase
> Primary key -> equipmentno
> Foreign Keys -> owner and incharge.
> The User hasMany Equipment.Equipment can be owned by only 1 person.
> I have created a form to add equipment.I need to validate the form by
> checking whether the user has entered a valid owner name or not.
> To do this I need to associate the models which I am unable to do.
> Could you please help me out.
> Thanks!

I would change your models slightly, so they follow the Cake
conventions more closely, to something like this:

// Tables
Users
- id (pk)
- name
- username
- password
- type
- email
- created
- modified

Equipments
- id (pk)
- user_id (fk)
- name
- equipment_number
- date_of_purchase
- created
- modified

Cake Models

User:
{
    var $hasMany = array('Equipment');
}

Equipment
{
    var $belongsTo = array('User');
}

You then need to populate a selectTag with your users, like so:

// equipments_controller()

funcrion add()
{
    $this->set('users', $this->Equipment->User->generateList());
}

// /app/views/equipments/add.thtml

echo $html->selectTag('Equipment/user_id', $users,
$html->tagValue('Equipment/user_id);

hth

jon


-- 


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

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