Re: Creating DatabaseTables (cakephp way)
I use this same concept but my userinformation is called profiles. just what i like but here is how mine our set up: users_controller.php: class UsersController extends AppController { var $name = 'Users'; var $scaffold; } user.php: class User extends AppModel { var $name = 'User'; var $hasOne = array( 'Profiles' => array('className' => 'Profiles', 'foreignKey' => 'users_id', 'dependent' => false ) ); } profiles_controller.php: class ProfilesController extends AppController { var $name = 'Profiles'; var $scaffold; } profile.php: class Profile extends AppModel { var $name = 'Profile'; var $belongsTo = array( 'Users' => array('className' => 'Users', 'foreignKey' => 'users_id' ) ); } going by your table setup - - - user table: id integer auto increment primary firstname varchar(45) lastname varchar(45) profile: id integer auto increment primary sss_number varchar(45) birthday datetime users_id integer primary this scenario works for me the id column in the profile table should be relevant to the profile table only . . . your association would be with the user_id field in the profile table and how you setup the relationship in your model (ex. 'foreignKey' => 'users_id' ) will make it work but this is how i do it . . rich On Nov 6, 8:18 am, Rey Philip <[EMAIL PROTECTED]> wrote: > By the way thnks for the responseActually what I want to do is the > "HasOne" relationship, the problem is that I can't implement it. The > problem is like this > > I have a users table: > id integer auto increment primary > firstname varchar(45) > lastname varchar(45) > > also I have a userinformations table > id integer auto increment primary > sss_number varchar(45) > birthday datetime > user_id integer > > I want this to have a one to one relationship > > so what I did in the userinformations_controller.php > > class UserinformationsController extends AppController > { > var $name = 'Userinformations'; > var $scaffold; > > } > > in the userinformation.php > > class Userinformation extends AppModel > { > var $ame = 'Userinformation'; > var $belongsTo = array('User'); > > } > > in the users_controller.php > > class UsersController extends AppController > { > var $name = 'User'; > var $scaffold; > > } > > in the user.php > > class User extends AppModel > { > var $name = 'User'; > var $hasOne = array('Userinformation'); > > } > > After doing that, I add new users to my users table and its > doneThe problem now is when I insert records on the > userinformations table, I cant insert 2 or more user_id in the > userinformations table. So I think the problem is on my table cause my > userinformations table has an auto_increment id and also the primary > key. So what I want to do is to delete the id in the userinformations > table and then make the user_id a primary key so, it will have a one > to one relationship with the user table. > > Am I right? Give me some advice on how to do it correctly. > > Good day. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Creating DatabaseTables (cakephp way)
By the way thnks for the responseActually what I want to do is the "HasOne" relationship, the problem is that I can't implement it. The problem is like this I have a users table: id integer auto increment primary firstname varchar(45) lastname varchar(45) also I have a userinformations table id integer auto increment primary sss_number varchar(45) birthday datetime user_id integer I want this to have a one to one relationship so what I did in the userinformations_controller.php class UserinformationsController extends AppController { var $name = 'Userinformations'; var $scaffold; } in the userinformation.php class Userinformation extends AppModel { var $ame = 'Userinformation'; var $belongsTo = array('User'); } in the users_controller.php class UsersController extends AppController { var $name = 'User'; var $scaffold; } in the user.php class User extends AppModel { var $name = 'User'; var $hasOne = array('Userinformation'); } After doing that, I add new users to my users table and its doneThe problem now is when I insert records on the userinformations table, I cant insert 2 or more user_id in the userinformations table. So I think the problem is on my table cause my userinformations table has an auto_increment id and also the primary key. So what I want to do is to delete the id in the userinformations table and then make the user_id a primary key so, it will have a one to one relationship with the user table. Am I right? Give me some advice on how to do it correctly. Good day. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Creating DatabaseTables (cakephp way)
In this case you'll have to tell Cake what the primary key is: http://book.cakephp.org/view/437/primaryKey Why would you want to name it this way though? An "id" column in the Category table is obviously going to be the "Category.id". "Category.category_id" seems pretty redundant to me, and in Cake conventions it looks like a belongsTo association field at first glance. On 6 Nov 2008, at 08:44, Rey Philip wrote: > > hi guys, > > I just would like to ask about creating tables. I have read a book > "Apress Beginning CakePHP" in chapter 2 it says there that > > "Giving each record a unique id value is essential for Cake to > function without trouble. > This application is simple, so you may be able to get by without > creating an id field set to > auto_increment. However, it’s good practice to make sure that all your > records in the database > can be identified by a unique value and that it’s named id, because > then Cake can generate > scaffolding around your table without any code on your part. Once you > begin creating associated > tables, then it will be mandatory to include an id field." > > My question is, I want to change the id field into another name, let's > say category_id. Example I have a category table like this. > > category_table > fields: category_id, name, description > > Will this work in the scaffolding feature? > > Here's my entire problemSample I have a not real world example > haha... > > products has one to one relationship with category. > > product has one category > category has one product > > product > fields: id, name, description > > category > fields category_id, name, description, product_id > > can this be possible using cake's scaffolding feature? > if possible how? > > Good day. > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Creating DatabaseTables (cakephp way)
hi guys, I just would like to ask about creating tables. I have read a book "Apress Beginning CakePHP" in chapter 2 it says there that "Giving each record a unique id value is essential for Cake to function without trouble. This application is simple, so you may be able to get by without creating an id field set to auto_increment. However, it’s good practice to make sure that all your records in the database can be identified by a unique value and that it’s named id, because then Cake can generate scaffolding around your table without any code on your part. Once you begin creating associated tables, then it will be mandatory to include an id field." My question is, I want to change the id field into another name, let's say category_id. Example I have a category table like this. category_table fields: category_id, name, description Will this work in the scaffolding feature? Here's my entire problemSample I have a not real world example haha... products has one to one relationship with category. product has one category category has one product product fields: id, name, description category fields category_id, name, description, product_id can this be possible using cake's scaffolding feature? if possible how? Good day. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---