0
votes

i would like to do a query search something like: select * from task t, activity a, project p where t.activityid = a.activityid and a.projectid = p.projectid and p.userid =25

I do understand my task, is related with activity, so how can i know the project created, task is related to the project.

in my task view-

$query1s = new Query;
$query1s->select('*')
    ->from('task','activity','project') 
    ->where(['task.activityid' => 'activity.activityid']) 
    ->andWhere(['activity.projectid' => 'project.projectid']) 
    ->andWhere(['project.userid' => $userID]);

$command = $query1s->createCommand();
$datas = $command->queryAll();

$dataProvider = new ActiveDataProvider([
    'query' => $query1s,
]);
1
show your code what you did.Yasin Patel
in my task view- $query1s = new Query; $query1s->select('*') ->from('task','activity','project') ->where(['task.activityid'=>'activity.activityid']) ->andWhere(['activity.projectid'=>'project.projectid']) ->andWhere(['project.userid'=>$userID]); $command = $query1s->createCommand();$datas = $command->queryAll(); $dataProvider = new ActiveDataProvider([ 'query' => $query1s, ]);james

1 Answers

0
votes

To achieve this you should create a search model from the main model and extend the search model class from the main model class.

After that you should create a public method called search with parameter. Then you do the filterings and querying data in your method without executing the query. When the query is completely created, just pass it to the dataprovider whitout executing it and you can do whatever you need to do with that data and handle other things in your controller and view.

Here is two URLs to complete tutorials to help you out:

Filter & Sort by calculated/related fields in GridView Yii 2.0

Displaying, Sorting and Filtering Model Relations on a GridView