I am building a social network and work on the users, requests, friends
portion.
users: id
requests: id, user_id, friend_id
friends: id, user_id, friend_id
I had setup the requests and friends tables to have user_id and friend_id
but they both point back to the users table. When working on the request
all is good. However, now I am trying to approve a request (delete from the
request table and put it into friend table) and have huge problems.
In the request controller on approve, I want to insert a new row into the
friends table, but because of the way the model is setup, it loads the User
model and not the Friend model. I am loading Friend on the fly but it is
still using the wrong table. Not sure how to make cakephp insert into that
row.
Code in the controller:
$friend = ClassRegistry::init('Friend');
$data = array();
//assign friend
array_push($data, array('user_id' =>
$this->Auth->user('id'), 'friend_id' => $id));
$this->Friend->save($data);
This calls save on the User model/table.
I have also tried unbinding Friend and loading a different one but now
luck. Any ideas on how to fix this, or a better way to handle the
requests/friends scenario?
Chad
Here are my models:
class Request extends AppModel {
var $name = 'Request';
var $validate = array(
'user_id' => array('numeric'),
'friend_id' => array('numeric')
);
//The Associations below have been created with all possible keys, those
that are not needed can be removed
var $belongsTo = array(
'User' => array('className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Friend' => array('className' => 'User',
'foreignKey' => 'friend_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
class Friend extends AppModel {
var $name = 'Friend';
var $validate = array(
'user_id' => array('numeric'),
'friend_id' => array('numeric')
);
//The Associations below have been created with all possible keys, those
that are not needed can be removed
var $belongsTo = array(
'User' => array('className' => 'User',
'foreignKey' => 'user_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Friend' => array('className' => 'User',
'foreignKey' => 'friend_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
}
The user model is pretty much blank.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---