I have a User table and a table for the cities, which I want to associate with each other. As you guess, a City can have multiple Users but one User can only be linked to one city.
I really don't know how to set my tables up. When I try $hasMany relation for the City and $hasOne for my User then I am getting an error, because the client_id field cannot be found in my cities table. My cities table is going to be fixed: no one will ever change the table. I just want to store some information about a city in this table.
Edit: Here are my tables and my models (kept simple):
clients { id, firstname, lastname, city_id }
cities { id, name, some_other_data }
And here are my models:
// User
class Client extends AppModel {
public $hasOne = array(
'City'
);
}
// City
class City extends AppModel {
public $useTable = 'cities';
public $hasMany = array(
'Client'
);
}