I have just begun to set up my site and am running into trouble when
trying to use the model associations.
My tables look like this.
CREATE TABLE city (
id INT UNSIGNED NOT NULL AUTO_INCREMEMNT,
name VARCHAR(50)
);
CREATE TABLE users (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
username VARCHAR(50),
city_id INT
);
Each user will be linked to ONLY one city, and each city will have
many users. So the best way I can think of to set up this model
association is to use the hasAndBelongsToMany for the cities so each
city will be assigned to a user. I have my models set up something
like this. (By the way when a user signs up a city_id is automatically
assigned to him that is the same as the id field in the city table)
<?php class City extends AppModel {
var $name = 'City';
var $hasAndBelongsToMany = array(
'User' =>
array('className' => 'User',
'conditions' => '',
order' => '',
'dependent' => true,
'foreignKey' => 'city_id'
}
I guess what I am confused about is how to properly set this up so
design will be easy. I am confused on the foreign key as well, is that
correct?
My goal to post stories that belong to the user's city_id. Do I have
this set up right or is there a better way to do what I am trying to
accomplish?
Thank you for any insight on the topic.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---