Yii Framework Forum: How To Select Other Table Column In $Criteria->Addincondition Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Select Other Table Column In $Criteria->Addincondition Yii Rate Topic: -----

#1 User is offline   rajkumar000000 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 18-September 12

Posted 13 February 2013 - 03:58 AM

i have 2 table
tbl_pricing (product_id, mobile_type, price)
and other table
tbl_product_index(product_id, product_name, index).

relation establish by the gii generated code..
in productindex.php
public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'pricing' => array(self::HAS_ONE, 'Pricing', 'product_id'),
			
		);
	}


and in
pricing.php

public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'product' => array(self::BELONGS_TO, 'ProductIndex', 'product_id'),
		);
	}

in ProductIndexController :
i want to select mobile_type column in addinCondition.how mobile_type column found in ProductIndexController .

here i use this code:
     public function actionIndex()
	{
$model = new ProductIndex();
 $product_id = (isset($_GET['ProductIndex']['product_id'])) ? $_GET['ProductIndex']['product_id'] : array();
 CVarDumper::dump($product_id);
    $criteria = new CDbCriteria();
    if( count( $product_id ) > 0 )
	{
	 $criteria->addInCondition( '`pricing`.`mobile_type`', $product_id, true, 'OR' );//how to select mobile_type column from tbl_pricing
	
	}
	$dataProvider = new CActiveDataProvider('ProductIndex',
	array('criteria'=>$criteria));
             $this->render('index',array(
            'dataProvider'=>$dataProvider,
			'model'=>$model,
            ));
			}


here i found an error:
Error 500: <h1>CDbException</h1>
<p>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pricing.mobile_type' in 'where clause'. The SQL statement executed was: SELECT COUNT(*) FROM `tbl_product_index` `t` WHERE `pricing`.`mobile_type`=:ycp0.

how to solve this error.
pls help me.
Any help is appreciated to me ....
thanks in advance..
0

#2 User is offline   rajkumar000000 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 18-September 12

Posted 13 February 2013 - 05:05 AM

anyone?
0

#3 User is offline   mirunho 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 170
  • Joined: 19-December 12
  • Location:Gdansk, Poland

Posted 13 February 2013 - 05:30 AM

View Postrajkumar000000, on 13 February 2013 - 03:58 AM, said:

i have 2 table
tbl_pricing (product_id, mobile_type, price)
and other table
tbl_product_index(product_id, product_name, index).

relation establish by the gii generated code..
in productindex.php
public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'pricing' => array(self::HAS_ONE, 'Pricing', 'product_id'),
			
		);
	}


and in
pricing.php

public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'product' => array(self::BELONGS_TO, 'ProductIndex', 'product_id'),
		);
	}

in ProductIndexController :
i want to select mobile_type column in addinCondition.how mobile_type column found in ProductIndexController .

here i use this code:
     public function actionIndex()
	{
$model = new ProductIndex();
 $product_id = (isset($_GET['ProductIndex']['product_id'])) ? $_GET['ProductIndex']['product_id'] : array();
 CVarDumper::dump($product_id);
    $criteria = new CDbCriteria();
    if( count( $product_id ) > 0 )
	{
	 $criteria->addInCondition( '`pricing`.`mobile_type`', $product_id, true, 'OR' );//how to select mobile_type column from tbl_pricing
	
	}
	$dataProvider = new CActiveDataProvider('ProductIndex',
	array('criteria'=>$criteria));
             $this->render('index',array(
            'dataProvider'=>$dataProvider,
			'model'=>$model,
            ));
			}


here i found an error:
Error 500: <h1>CDbException</h1>
<p>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pricing.mobile_type' in 'where clause'. The SQL statement executed was: SELECT COUNT(*) FROM `tbl_product_index` `t` WHERE `pricing`.`mobile_type`=:ycp0.

how to solve this error.
pls help me.
Any help is appreciated to me ....
thanks in advance..


Please try to use
                $criteria->with = array(
                    'pricing' => array(
                        'together' => true,
                    )

0

#4 User is offline   rajkumar000000 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 18-September 12

Posted 13 February 2013 - 05:50 AM

View Postrajkumar000000, on 13 February 2013 - 03:58 AM, said:

i have 2 table
tbl_pricing (product_id, mobile_type, price)
and other table
tbl_product_index(product_id, product_name, index).

relation establish by the gii generated code..
in productindex.php
public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'pricing' => array(self::HAS_ONE, 'Pricing', 'product_id'),
			
		);
	}


and in
pricing.php

public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'product' => array(self::BELONGS_TO, 'ProductIndex', 'product_id'),
		);
	}

in ProductIndexController :
i want to select mobile_type column in addinCondition.how mobile_type column found in ProductIndexController .

here i use this code:
     public function actionIndex()
	{
$model = new ProductIndex();
 $product_id = (isset($_GET['ProductIndex']['product_id'])) ? $_GET['ProductIndex']['product_id'] : array();
 CVarDumper::dump($product_id);
    $criteria = new CDbCriteria();
    if( count( $product_id ) > 0 )
	{
	 $criteria->addInCondition( '`pricing`.`mobile_type`', $product_id, true, 'OR' );//how to select mobile_type column from tbl_pricing
	
	}
	$dataProvider = new CActiveDataProvider('ProductIndex',
	array('criteria'=>$criteria));
             $this->render('index',array(
            'dataProvider'=>$dataProvider,
			'model'=>$model,
            ));
			}


here i found an error:
Error 500: <h1>CDbException</h1>
<p>CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'pricing.mobile_type' in 'where clause'. The SQL statement executed was: SELECT COUNT(*) FROM `tbl_product_index` `t` WHERE `pricing`.`mobile_type`=:ycp0.

how to solve this error.
pls help me.
Any help is appreciated to me ....
thanks in advance..



i did it....
i m using this code for take the other table column...
 public function actionIndex()
	{
	$model = new ProductIndex();
    $product_id = (isset($_GET['ProductIndex']['product_id'])) ? $_GET['ProductIndex']['product_id'] : array();
    CVarDumper::dump($product_id);
	 $model = new ProductIndex();
     $criteria = new CDbCriteria();
	 //take the other table column
	 $criteria->with = 'pricing'; 
	 $criteria->together = true; 
	 $productindex = ProductIndex::model()->with('pricing')->findAll($criteria);
   if( count( $product_id ) > 0 )
	{
	 $criteria->addInCondition( 'pricing.mobile_type', $product_id );
	
	}
	$dataProvider = new CActiveDataProvider('ProductIndex',
	array('criteria'=>$criteria));
             $this->render('index',array(
            'dataProvider'=>$dataProvider,
			'model'=>$model,
            ));
			}

0

#5 User is offline   rajkumar000000 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 18-September 12

Posted 13 February 2013 - 05:58 AM

View Postmirunho, on 13 February 2013 - 05:30 AM, said:

Please try to use
                $criteria->with = array(
                    'pricing' => array(
                        'together' => true,
                    )




a lot of thanks mirunho...
i also try it and found the same answer..
thanks
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users