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 <reyphilipre...@gmail.com> wrote:
> By the way thnks for the response....Actually 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
> done....The 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 cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment