I m having problem with managing relations between two tables user and questions can anyone help me with this.
user table
userId
year,
question table
userId
question,
I have tried this
in question 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(
'user'=> array(self::BELONGS_TO, 'User', 'userId'),
);
}
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(
'question' => array(self::HAS_MANY,'Question','userId'),
);
}
and have tried all methods like findAll() and user::model()->with(‘user’)->findAll();
please, show me more detail about database structure and model class
user table
userId
year,
question table
userId
question,
where 's the id field of question ?
I saw your relations method
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(
'question' => array(self::HAS_MANY,'Question','userId'),
);
}
Well, you keep saying “It’s not working” but you didn’t show what you have tried and what error message that you got if any. I think Chung Tran’s answer should solve your problem, but you said it’s not working, so what’s the error message or what’s the result that you think an error?