I have two tables:
users{
id
username
password
}
person{
id
fname
lname
user_id
}
and relation in User model:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'person'=>array(self::HAS_ONE, 'Person', 'user_id'),
);
}
In tutorial there was said I can delete both by writting in user controller:
$this->loadModel($id)->person->delete();
but it deletes only person record in db.
and if I write:
$this->loadModel($id)->with('person')->delete();
This deletes only user record in db.
How can I delete both using these relations or changing them perhaps?
Of course I could write that in 3 lines:
$user=$this->loadModel($id);
Person::model()->findByPk($user->person_id)->delete();
$user->delete();
and it would delete both.