Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Nested Relational criteria in search()

$
0
0
I've just spent a few hours trying to figure this out, turns out you can nest relational criteria in the search() function in a model.

Like this:
$criteria->with = array('event' => array('with' => 'student_user'));
$criteria->compare("student_user.username", $this->student_username, true);


Both 'event' and 'student_user' are BELONGS_TO relations. 'student_username' is a public variable defined at the beginning of my model (and set as safe in my rules). I've been trying use the following in my CGridView widget columns:

array(
    'name' => 'student_username',
    'header' => 'Student',
    'type' => 'raw',
    'value' => '$data->event->student_user->username'
),


The nested criteria helped me get the search function working, hope this helps someone :)

jc

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>