lithium\tests\cases\data\source\DatabaseTest::testWithOptionAndInlineConstraint PHP Метод

testWithOptionAndInlineConstraint() публичный Метод

    public function testWithOptionAndInlineConstraint()
    {
        $model = $this->_gallery;
        $options = array('type' => 'read', 'model' => $model, 'with' => array('Image' => array('constraints' => array('Image.title' => (object) "'MyImage'")), 'Image.ImageTag.Tag' => array('constraints' => array('Tag.name' => (object) "'MyTag'"))));
        $result = $this->_db->read(new Query($options));
        $expected = 'SELECT * FROM {mock_gallery} AS {Gallery} ';
        $expected .= 'LEFT JOIN {mock_image} AS {Image} ON {Image}.{title} = \'MyImage\' ';
        $expected .= 'AND {Gallery}.{id} = {Image}.{gallery_id} LEFT JOIN ';
        $expected .= '{mock_image_tag} AS {ImageTag} ON ';
        $expected .= '{Image}.{id} = {ImageTag}.{image_id} LEFT JOIN {mock_tag} AS {Tag} ON ';
        $expected .= '{Tag}.{name} = \'MyTag\' AND {ImageTag}.{tag_id} = {Tag}.{id};';
        $this->assertEqual($expected, $this->_db->sql);
        $to = 'lithium\\tests\\mocks\\data\\model\\MockImage';
        $model::bind('hasMany', 'Image', array('to' => $to));
        $to::bind('belongsTo', 'Gallery', array('to' => $model));
        $result = $this->_db->read(new Query(array('type' => 'read', 'model' => $model, 'with' => array('Image.Gallery' => array('alias' => 'Gallery2', 'constraints' => array('Gallery.custom_id' => 'Gallery2.id'))))));
        $expected = 'SELECT * FROM {mock_gallery} AS {Gallery} LEFT JOIN {mock_image} AS {Image}';
        $expected .= ' ON {Gallery}.{id} = {Image}.{gallery_id} LEFT JOIN {mock_gallery} AS ';
        $expected .= '{Gallery2} ON {Gallery}.{custom_id} = {Gallery2}.{id} AND ';
        $expected .= '{Image}.{gallery_id} = {Gallery2}.{id};';
        $this->assertEqual($expected, $this->_db->sql);
        $model::reset();
    }
DatabaseTest