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

$Condition With Related Models In Cactivedataprovider

$
0
0
I have the following tables:
CREATE TABLE w2w_schedule
(
    id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
    shift_type varchar(10),
    date date NOT NULL,
    start varchar(7) NOT NULL,
    end varchar(7) NOT NULL,
    assignment_type int NOT NULL
);


and
CREATE TABLE w2w_shift_employee
(
    id int PRIMARY KEY NOT NULL AUTO_INCREMENT,
    shift_id int NOT NULL,
    employee_id int NOT NULL,
    notes varchar(7)
);


with the following relations:
in shift_employee...
        
return array(
            'schedule' => array(self::BELONGS_TO, "W2wSchedule", 'shift_id'),
        );
    }


and in schedule
        return array(
            'shift_employees' => array(self::HAS_MANY, "W2wShiftEmployee", 'id'),
        );


and I'm trying to create a activeDataProvider to search for a range of date(s) combining both tables. I have the following ADP:
    $date = '2012-12-13';
    $dataProvider=new CActiveDataProvider('W2wShiftEmployee', array(
        'criteria'=>array(
            'with'=> array('schedule'=>
                array('select'=>'t.id,w2w_schedule.date,w2w_schedule.start,w2w_schedule.end'),
                array('condition'=> 't.shift_id = w2w_schedule.id'),
                array('condition'=> "w2w_schedule.date = `$date`")
            ),
            'together'=> true,
        ),
        'pagination'=>array(
            'pageSize'=>10,
        ),
    ));

I'm getting no errors, however the last condition is not being used and Im getting ALL W2w_shift_employee records with the corresponding w2w_schedule data. Please help!

Marquis

Viewing all articles
Browse latest Browse all 18717

Trending Articles



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