重置关系中的默认范围,Yii 1.1

时间:2015-10-08 06:07:30

标签: php activerecord yii yii1.x

如何重置关系中的默认范围?

查询:

 <?php
    $autopost_controler = get_theme_mod( 'auto_onoff' );
    if( $autopost_controler != '' ) {
    switch ( $autopost_controler ) {
        case 'on': 

add_action('add_attachment', 'auto_post_on_image_upload'); 
function auto_post_on_image_upload($attachId)
{
$attachment = get_post($attachId);
$image = wp_get_attachment_image_src( $attachId, 'large');
$image_tag = '<p><img src="'.$image[0].'" /></p>';
$cidargs = array('category_name' => get_theme_mod('cat_1'));
$cid = array(get_category_by_slug($cidargs['category_name'])->term_id);
$theoriginaltitle = $attachment->post_title;
$onetitle = str_replace("-"," ",$theoriginaltitle);
$thetitlef = str_replace("_"," ",$onetitle);
$thetitle = ucwords(strtolower($thetitlef));
$content = '<strong>'. $thetitle .' </strong> is a funny photo posted in <strong>'.$cidargs['category_name'].'</strong> category. If you like <strong>'. $thetitle .'</strong> funny image, please share it with your friends.';

$alltags =  $thetitle;
$createtags = explode(" ", $alltags); 

 $postData = array(
    'post_title' => $thetitle,
    'post_type' => 'post',
    'post_content' => $content,
    'post_category' => $cid,
    'tags_input' =>  $createtags,
    'post_status' => 'publish'
);
$post_id = wp_insert_post($postData);
// attach media to post

wp_update_post(array(
    'ID' => $attachId,
    'post_parent' => $post_id
));
set_post_thumbnail($post_id, $attachId);
return $attachId;
}


break;
        case 'off':  
        break;

        }
}

功能关系():

$matches = MatchesStat::model()
->resetScope(true)
->with(array('best_player', 'bad_player'))
->findByAttributes(array(
            'match_id' => $this->id,
            'mode' => $this->mode
        ));

玩家,defaultScope:

public function relations()
{
    return array(
        'best_player'=>array(self::BELONGS_TO, 'Players', '', 'on' => 't.best_pl = best_player.pl_id AND t.mode = best_player.mode', 'scopes' => array( 'resetScope' )),
        'bad_player'=>array(self::BELONGS_TO, 'Players', '', 'on' => 't.bad_pl = bad_player.pl_id AND t.mode = bad_player.mode', 'scopes' => array( 'resetScope' ))
    );
}

如您所见,我使用'scopes'=&gt;我的关系中的数组('resetScope')。但是:

enter image description here

0 个答案:

没有答案